diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-09-26 00:17:06 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-30 09:47:05 +0200 |
commit | ec5d846ac6137e60d81257041e4fde82c0480b32 (patch) | |
tree | 4a0fb0b3eb176c908c68b8f01e3b3697a6522133 /railties/lib/rails/engine.rb | |
parent | 22b11a41cc764bc0f7b0c0f518a5289230428597 (diff) | |
download | rails-ec5d846ac6137e60d81257041e4fde82c0480b32.tar.gz rails-ec5d846ac6137e60d81257041e4fde82c0480b32.tar.bz2 rails-ec5d846ac6137e60d81257041e4fde82c0480b32.zip |
Properly reload routes defined in class definition
Sometimes it's easier to define routes inside Engine or
Application class definition (e.g. one file applications). The
problem with such case is that if there is a plugin that
has config/routes.rb file, it will trigger routes reload on application.
Since routes definition for application is not in config/routes.rb
file routes_reloader will fail to reload application's routes
properly. With this commit you can pass routes definition as a block
to routes method, which will allow to properly reload it:
class MyApp::Application < Rails::Application
routes do
resources :users
end
end
Diffstat (limited to 'railties/lib/rails/engine.rb')
-rw-r--r-- | railties/lib/rails/engine.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index ababf6a242..aa82a82b19 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -399,8 +399,10 @@ module Rails } end - def routes + def routes(&block) @routes ||= ActionDispatch::Routing::RouteSet.new + self.routes_draw_block = block if block_given? + @routes end def initializers @@ -447,6 +449,7 @@ module Rails end initializer :add_routing_paths do |app| + app.routes_to_reload[self.routes] = routes_draw_block paths.config.routes.to_a.each do |route| app.routes_reloader.paths.unshift(route) if File.exists?(route) end @@ -499,6 +502,8 @@ module Rails end protected + attr_accessor :routes_draw_block + def find_root_with_flag(flag, default=nil) root_path = self.class.called_from |