Rails給我的URL有錯誤的順序。它將父母標識交給孩子,孩子標識交給父母。Rails將我的calendar_event_path向後路由?
在我的routes.rb我有
resources :calendars do
resources :events
end
這rake routes
告訴我,是建立良好的途徑,例如
calendar_event GET /calendars/:calendar_id/events/:id(.:format) {:controller=>"events", :action=>"show"}
所以,當我詢問從我的觀點部分是路由路徑,
<%= link_to "#{event.name} @ #{event.calendar.name} #{event.calendar.year}", calendar_event_path(event) %>
它讓我有逆轉的ID網址...
http://localhost:3000/calendars/<-eventid->/events/<-calendarid->
任何幫助將不勝感激!
編輯:在我的模型中,事件belongs_to :calendar
和日曆has_many :events
。我也使用Mongoid作爲我的ORM,而不是ActiveRecord,儘管我希望這不是問題。
輝煌!謝謝!這固定了它! – 2011-05-30 02:54:21
進一步解釋:如果你沒有傳遞一個有效的ID,那麼Rails會假定你是指當前參數,所以如果設置了'params [:id]',它就會假設。 – 2011-05-30 04:03:05