rails - url_for behaving differently when using namespace (based on current controller being used)
ruby-on-rails
Solution
From here: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
The last note box reads:
If you need to use a different controller namespace inside a namespace block you can specify an absolute controller path, e.g: get '/foo' => '/foo#index'.
This means all you have to do is this:
url_for({ controller: "/abcs", action: :new })
I ran into this problem as well and this solves it :)
Problem
lets assume namespace is "abc", we have a controller "abcs" and another one that uses namespace "abc" is "defs". for easy understanding: ``` AbcsController Abc::DefsController ``` When current flow is in `AbcsController`, `url_for({:controller => "abcs", :action => :new})` is returning correct url but when flow is in `Abc::DefsController`, when I am giving: ``` url_for({:controller => "abcs", :action => :new }) ``` It is treating it as: ``` url_for({:controller => "abc/abcs", :action => :new}) #Observe abc/abcs ``` So, here it should be "abcs" but not "abc/abcs" but it is treating like that. Whats the solution? Please ask me fr more information.