Skip to content

Commit 9d0c3fb

Browse files
committed
Don't mount routes to top-level context
Don't mount route helpers at top-level. For instance, while serving an Ember application from `/admin/editor`, the application could be mounted like this: ```rb mount_ember_app :admin, to: "/admin/editor" ``` The previous implementation allows for this, as it was written with this use case in mind. Alternatively, the application could be mounted from within a `namespace`, `scope`, or `constraint` block. Unfortunately, the previous implementation doesn't support these use cases, since the routes are mounted at the global level (i.e. in the first line of a `Rails.application.routes.draw` block). This commit adds support for the latter case, taking into account the surrounding context with which the route helpers are invoked.
1 parent 0482a46 commit 9d0c3fb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ master
22
------
33

44
* Fix bug with generated `bin/heroku_install` script iterating through multiple
5-
Ember application's directories.
5+
* Don't mount route helpers at top-level. Instead, mount within the surrounding
6+
context with which they're invoked. [#381]
7+
8+
[#381]: https://github.com/thoughtbot/ember-cli-rails/pull/381
69

710
0.7.0
811
-----

lib/ember_cli/route_helpers.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ def mount_ember_app(app_name, to:, **options)
1414
format: :html,
1515
)
1616

17-
Rails.application.routes.draw do
18-
scope constraints: EmberCli::HtmlConstraint.new do
19-
get("#{to}(*rest)", routing_options)
20-
end
17+
scope constraints: ::EmberCli::HtmlConstraint.new do
18+
get("#{to}(*rest)", routing_options)
19+
end
2120

22-
dist_directory = EmberCli[app_name].paths.dist
21+
dist_directory = ::EmberCli[app_name].paths.dist
2322

24-
mount Rack::File.new(dist_directory.to_s) => to
25-
end
23+
mount Rack::File.new(dist_directory.to_s) => to
2624
end
2725
end
2826
end

0 commit comments

Comments
 (0)