2010-12-10 9 views
0

이것은 매우 어리석은 질문이지만 실제 문제를 파악하는 데 어려움이 있습니다. 다음 경로를 레일즈 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 

난이 도움이되기를 바랍니다!