开发者

How do I map a resource the root of an application in Rails 3?

In routes.rb, I'm using resources to declare all common routes for a controller:

resources :photos

This creates URLs which look like this:

http://example.com/photos
http://example.com/photos/new
...

How do I remove photos from the URLs? That is, h开发者_JS百科ow do I map this controller to the root of the application?


You can route a resourceful controller to the root by adding the path option:

resources :photos, :path => "/"

And, of course, this can still be extended in the usual way;

resources :photos, :path => "/" do
  member do
    get 'view_original_size'
  end
end

For more information, see Module ActionDispatch::Routing::Mapper::Resources > resources > Supported options in the API documentation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜