我可以在應用程序中顯示上一個和下一個鏈接,但我試圖弄清楚如果我的鏈接有嵌套路由會發生什麼?Rails:處理嵌套路由時的上一個/下一個記錄
例如我的鏈接是
localhost:3000/users/1/photos/2
我在我的模型有這些:
def previous_img
self.class.first(:conditions => ["created_at < ?", created_at], :order => "created_at desc")
end
def next_img
self.class.first(:conditions => ["created_at > ?", created_at], :order => "created_at asc")
end
,並在我的意見我有這樣的:
<%= link_to "Previous", @photo.previous_img if @photo.previous_img %>
<%= link_to "Next", @photo.next_img if @photo.next_img %>
這些鏈接將直接我到沒有users/1
的鏈接,它只會給我
localhost:3000/photos/1 # for previous
localhost:3000/photos/3 # for next
有沒有辦法,也許我可以連接users/1
或實際的方法來獲得嵌套路線在這件事上?
感謝
可能重複[鋼軌:「下一篇」在我型我秀觀「上一篇」鏈接,怎麼以?](http://stackoverflow.com/questions/1275963/rails-next-post-and-previous-post-links-in-my-show-view-how-to) –