mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
6c95e0f879
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)
26 lines
562 B
Ruby
26 lines
562 B
Ruby
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
|