2010-12-10 4 views
0

これはかなりばかげた質問ですが、私は実際の問題を理解しています。私は(2.8.xから)Railsの3のため、それに準拠するために、次のルートを変換したい:レールのルートを変換する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見えるようにしたいなら、あなたはそうのように、一度にそれらを1つを指定することができます。

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 

私はこれが役に立てば幸い!

関連する問題