开发者

How to default all routes to a specific folder in Rails?

I have a folder called home that I'm using to organize my top level view files. How do I set the route so t开发者_如何转开发hat when they appear the url doesn't contain the /home/ section.

Example: Currently the file about_us displays http://somesite.com/home/about_us where I want it to display http://somesite.com/about_us

Thanks


match is specific to rails 3. to handle this in rails 2.3.8 you want to do this:

map.about_us "/about", :controller => "home", :action => "about_us"  


One way would be to do this:

match 'about_us', :to => "home#about_us"

If you have multiple actions you want to perform in this way, use this:

match ':action', :controller => "home"


Rails 2.x way of doing this is

map.connect "/:action", :controller => "home"

this will map somesite.com/somepage to the somepage action on the HomeController

If you want to use a single action for everything, you may go for

map.connect "/:page", :controller => "home", :action => "page"

and then in your HomeController

class HomeController < ActionController::Base
  def page
    render params[:page]
  end
end

and of course, with this setup, you can name your views in app/views/home after the actual page names

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜