From 6c95e0f879aafa5921cd7898d5951b9a926d3c9a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 18 Jul 2010 19:49:51 +0200 Subject: Add mounted_helpers to routes mounted_helpers are a bit similar to url_helpers. They're automatically included in controllers for Rails.application and each of mounted Engines. Mounted helper allows to call url_for and named helpers for given application. Given Blog::Engine mounted as blog_engine, there are 2 helpers defined: app and blog_engine. You can call routes for app and engine using those helpers: app.root_url app.url_for(:controller => "foo") blog_engine.posts_path blog_engine.url_for(@post) --- actionpack/lib/action_controller/railtie.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/railtie.rb') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index cd2dfafbe6..7496dd57b2 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -51,6 +51,7 @@ module ActionController ActiveSupport.on_load(:action_controller) do include app.routes.url_helpers + include app.routes.mounted_helpers(:app) options.each { |k,v| send("#{k}=", v) } end end @@ -63,4 +64,4 @@ module ActionController ActionController::Routing::Routes = proxy end end -end \ No newline at end of file +end -- cgit v1.2.3 From c7664d112fadb313146da33f48d1da318f249927 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 30 Jul 2010 07:14:48 +0200 Subject: Include application's helpers and router helpers by default, but include engine's ones for controllers inside isolated namespace --- actionpack/lib/action_controller/railtie.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/railtie.rb') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 7496dd57b2..23622b19e8 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -4,6 +4,7 @@ require "action_dispatch/railtie" require "action_view/railtie" require "active_support/deprecation/proxy_wrappers" require "active_support/deprecation" +require "action_controller/railties/routes_helpers" module ActionController class Railtie < Rails::Railtie @@ -50,7 +51,7 @@ module ActionController options.helpers_path ||= paths.app.helpers.to_a ActiveSupport.on_load(:action_controller) do - include app.routes.url_helpers + extend ::ActionController::Railties::RoutesHelpers.with(app.routes) include app.routes.mounted_helpers(:app) options.each { |k,v| send("#{k}=", v) } end -- cgit v1.2.3 From 4131a2d804c54960ac70984e7453069fe8688365 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Aug 2010 17:38:44 +0200 Subject: Move ActionController::Railties::RoutesHelpers and ActionMailer::Railties::RoutesHelper to AbstractController::Railties::RoutesHelpers --- actionpack/lib/action_controller/railtie.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller/railtie.rb') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 23622b19e8..4b5a897b90 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -4,7 +4,7 @@ require "action_dispatch/railtie" require "action_view/railtie" require "active_support/deprecation/proxy_wrappers" require "active_support/deprecation" -require "action_controller/railties/routes_helpers" +require "abstract_controller/railties/routes_helpers" module ActionController class Railtie < Rails::Railtie @@ -51,7 +51,7 @@ module ActionController options.helpers_path ||= paths.app.helpers.to_a ActiveSupport.on_load(:action_controller) do - extend ::ActionController::Railties::RoutesHelpers.with(app.routes) + extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) include app.routes.mounted_helpers(:app) options.each { |k,v| send("#{k}=", v) } end -- cgit v1.2.3 From e5af8b7d85abb94f21f4e873c1c267e27be2aad8 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 6 Aug 2010 16:34:48 +0200 Subject: Moved ActionMailer and ActionController railties options to inherited hook This change is needed, because we must take namespace into account and if controller's/mailer's class is namespaced, engine's paths should be set instead of application's ones. The nice side effect of this is removing unneeded logic in ActionController::Base.inherited - now the helpers_path should be set correctly even for engine's controllers, so helper(:all) will always include correct helpers. --- actionpack/lib/action_controller/railtie.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'actionpack/lib/action_controller/railtie.rb') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 4b5a897b90..2271a51e4e 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -5,6 +5,7 @@ require "action_view/railtie" require "active_support/deprecation/proxy_wrappers" require "active_support/deprecation" require "abstract_controller/railties/routes_helpers" +require "action_controller/railties/paths" module ActionController class Railtie < Rails::Railtie @@ -41,19 +42,10 @@ module ActionController end initializer "action_controller.set_configs" do |app| - paths = app.config.paths - options = app.config.action_controller - - options.assets_dir ||= paths.public.to_a.first - options.javascripts_dir ||= paths.public.javascripts.to_a.first - options.stylesheets_dir ||= paths.public.stylesheets.to_a.first - options.page_cache_directory ||= paths.public.to_a.first - options.helpers_path ||= paths.app.helpers.to_a - ActiveSupport.on_load(:action_controller) do - extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) include app.routes.mounted_helpers(:app) - options.each { |k,v| send("#{k}=", v) } + extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) + extend ::ActionController::Railties::Paths.with(app) end end -- cgit v1.2.3 From 98ab4ded376c3d04540bdbdfe6dbbf88c0738701 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 23 Aug 2010 18:31:29 +0200 Subject: Set only helpers_path on inherited hook in action_controller/railtie.rb and use helper(:all) just after that --- actionpack/lib/action_controller/railtie.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/lib/action_controller/railtie.rb') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 2271a51e4e..0cb4041855 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -42,10 +42,19 @@ module ActionController end initializer "action_controller.set_configs" do |app| + paths = app.config.paths + options = app.config.action_controller + + options.assets_dir ||= paths.public.to_a.first + options.javascripts_dir ||= paths.public.javascripts.to_a.first + options.stylesheets_dir ||= paths.public.stylesheets.to_a.first + options.page_cache_directory ||= paths.public.to_a.first + ActiveSupport.on_load(:action_controller) do include app.routes.mounted_helpers(:app) extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) extend ::ActionController::Railties::Paths.with(app) + options.each { |k,v| send("#{k}=", v) } end end -- cgit v1.2.3