diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-07-18 19:49:51 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:07 +0200 |
commit | 6c95e0f879aafa5921cd7898d5951b9a926d3c9a (patch) | |
tree | d327320b3349b8a3359ca7c16e92f72fce2a92a6 /actionpack/lib/action_controller | |
parent | e9791bec823e42372eca095b946c93c1712a0613 (diff) | |
download | rails-6c95e0f879aafa5921cd7898d5951b9a926d3c9a.tar.gz rails-6c95e0f879aafa5921cd7898d5951b9a926d3c9a.tar.bz2 rails-6c95e0f879aafa5921cd7898d5951b9a926d3c9a.zip |
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)
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/railtie.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_controller/railties/url_helpers.rb | 26 |
2 files changed, 28 insertions, 1 deletions
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 diff --git a/actionpack/lib/action_controller/railties/url_helpers.rb b/actionpack/lib/action_controller/railties/url_helpers.rb new file mode 100644 index 0000000000..3e6f211cda --- /dev/null +++ b/actionpack/lib/action_controller/railties/url_helpers.rb @@ -0,0 +1,26 @@ +module ActionController + module Railties + + module UrlHelpers + def self.with(routes) + Module.new do + define_method(:inherited) do |klass| + super(klass) + klass.send(:include, routes.url_helpers) + end + end + end + end + + module MountedHelpers + def self.with(routes, name = nil) + Module.new do + define_method(:inherited) do |klass| + super(klass) + klass.send(:include, routes.mounted_helpers(name)) + end + end + end + end + end +end |