开发者

Namespaced routes

开发者 https://www.devze.com 2023-02-13 02:24 出处:网络
I must be missing something with this rather trivial routes implementation in Rails 3. I have a namespaced route like so:

I must be missing something with this rather trivial routes implementation in Rails 3.

I have a namespaced route like so:

namespace 'dashboard' do
  get 'download', to: "Index#download"
end

If I run rake routes I see:

dashboard_download  GET  /dashboard/download(.:format) {:action=>"download", :controller=>"dashboard/Index"}

The URL is super, that's exactly what I want (and will have many more matches in the namespace), but the controller is wrong. It should just be Index, not dashboard/Index.

Is there any开发者_运维百科 way of fixing this? Or is that the wrong way to implement that style of route?

Cheers.


To remove the module prefix do this:

scope '/dashboard' do
  get 'download', to: "Index#download"
end

You can find more information and alternatives here.

0

精彩评论

暂无评论...
验证码 换一张
取 消