2013-06-07 2 views
2

대신에 다른 속성을 사용 LINK_TO 만들려면 다음 줄을 things/:id레일 : ID

link_to "Thing", @thing 

에 대한 링크를 만듭니다하지만 things/:some_other_id에 대한 링크를 작성해야합니다.

내 첫 번째 생각은 /things/:id의 경로를 /things/:some_other_id으로 변경하면 효과가 있지만 그럴 수는 없다고 생각했습니다.

내가 명시 적으로 some_other_idanother_path을 표시하지 않고 다음을 수행해야합니다

link_to "Thing", another_path(@thing.some_other_id) 

답변

3

좋아, 내가 해결책을 찾은 것 같아요. Thing.id을 기본값으로 반환하는 Thing.to_param을 재정의해야합니다.

+1

예, http://api.rubyonrails.org/v2.3.8/classes/ActiveRecord/Base.html#M001851 – Salil

0
match "/things/:some_other_id" => "things#some_action" 

라우트 파일에서 이것을 정의하여 resources :things 행 앞에 배치 할 수 있습니다.