In Rails, is it possible to namespace models in modules and still get correct behavior from url_for
?
For instance, here, url_for
works as e
Use
namespace "blah" do
resources :thing
end
Then routes will be named appropiately.
rake routes
To view all routes
Specify the module on the route
resources :users, :module => "m"
or use scope to do it
scope :module => "m" do
resources :users
end
Just define use_relative_model_naming?
in the containing module to avoid prefixing the generated route names:
module M
def self.use_relative_model_naming?
true
end
end
In my case I overridden the url_for method on my application_helper.rb file to add the :network param on all routes from my namespace :mkp.
module ApplicationHelper
def url_for(options = {})
if options.is_a?(Hash) && options.has_key?(:controller)
if options[:network].nil? && options[:controller].match(/^mkp\//).present?
options[:network] = @network.downcase
end
end
super(options)
end
end