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.
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 :)
url_for
also can take an array as an argument, you are probably looking for something like:
url_for([:edit, :admin, @product])
where the admin
symbol would be your namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With