2010-12-10 171 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 

我希望這有助於!