2010-12-10 95 views
0

这是一个非常愚蠢的问题,但我有一些真正的麻烦搞清楚。我想转换下面的路线,使其符合Rails 3(从2.8.x):转换轨道3

map.with_options :controller => 'static_pages', :action => 'show' do |static_page| 
     static_page.faq 'faq', :id => 'faq' 
     static_page.about 'about', :id => 'about' 
     static_page.blog 'blog', :id => 'blog' 
     static_page.support 'support', :id => 'support' 
     static_page.privacy 'privacy', :id => 'privacy' 
     static_page.howitworks 'howitworks', :id => 'howitworks' 
     static_page.contact 'contact', :id => 'contact' 
     static_page.terms_and_conditions 'terms_and_conditions', :id => 'terms_and_conditions' 
    end 

任何帮助将不胜感激!

回答

1

我想我会做这样的:

scope '/static_pages', :name_prefix => 'static_page', :to => 'static_pages#show' do 
    for page in %w{ faq about blog support privacy howitworks contact terms_and_conditions } 
     match page, :id => page 
    end 
    end 
1

这是真棒,我只是写了一篇关于这几个星期前:

Routing in Ruby on Rails 3

它越过转换的大多数方面,具有下载的示例应用程序。虽然我没有专门介绍with_options转换,但我可以在这里做一点。下面是一个简短的方式:

scope :static_pages, :name_prefix => "static_page" do 
    match "/:action", :as => "action" 
end 

这所有的路由匹配你有以上,和你的命名路由应该是这样的:

static_page_path(:faq) 
static_page_path(:about) 

...等等。如果你希望你的命名路由仍然看起来像static_page_faq_path那么你就可以在指定的时间一个一个地,像这样:

scope '/static_pages', :name_prefix => 'static_page' do 
    match '/faq', :to => 'static_pages#faq' 
    match '/about', :to => 'static_pages#about' 
    # fill in all the rest here 
end 

我希望这有助于!