Skip to content

Commit fc52a04

Browse files
committed
Merge pull request #135 from jluckyiv/patch-1
Update README with alternate route instructions
2 parents 254da41 + 91f7952 commit fc52a04

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,69 @@ could render your app at the `/` route with the following view:
122122

123123
Your Ember application will now be served at the `/` route.
124124

125+
### Other routes
126+
127+
Rendering Ember applications at routes other than `/` requires additional setup to avoid an Ember `UnrecognizedURLError`.
128+
129+
For instance, if you had Ember applications named `:frontend` and `:admin_panel` and you wanted to serve them at `/frontend` and `/admin_panel`, you would set up the following Rails routes:
130+
131+
```rb
132+
# /config/routes.rb
133+
Rails.application.routes.draw do
134+
root 'application#index'
135+
get 'frontend' => 'frontend#index'
136+
get 'admin_panel' => 'admin_panel#index'
137+
end
138+
139+
# /app/controllers/frontend_controller.rb
140+
class FrontendController < ActionController::Base
141+
def index
142+
render :index
143+
end
144+
end
145+
146+
# /app/controllers/admin_panel_controller.rb
147+
class AdminPanelController < ActionController::Base
148+
def index
149+
render :index
150+
end
151+
end
152+
```
153+
154+
Additionally, you would have to modify each Ember app's `baseURL` to point to the correct route:
155+
156+
```javascript
157+
/* /app/frontend/config/environment.js */
158+
module.exports = function(environment) {
159+
var ENV = {
160+
modulePrefix: 'frontend',
161+
environment: environment,
162+
baseURL: '/frontend', // originally '/'
163+
...
164+
}
165+
}
166+
167+
/* /app/admin_panel/config/environment.js */
168+
module.exports = function(environment) {
169+
var ENV = {
170+
modulePrefix: 'admin_panel',
171+
environment: environment,
172+
baseURL: '/admin_panel', // originally '/'
173+
...
174+
}
175+
}
176+
```
177+
Lastly, you would configure each app's `router.js` file so that `rootURL` points to the `baseURL` you just created:
178+
179+
```javascript
180+
/* app/frontend/app/router.js */
181+
var Router = Ember.Router.extend({
182+
rootURL: config.baseURL, // add this line
183+
location: config.locationType
184+
});
185+
```
186+
Repeat for `app/admin_panel/app/router.js`. Now your Ember apps will render properly at the alternative routes.
187+
125188
## CSRF Tokens
126189

127190
Your Rails controllers, by default, are expecting a valid authenticity token to be submitted with non-`GET` requests.

0 commit comments

Comments
 (0)