Does Rails route my event_path calendar back?

Rails gives me URLs that have identifiers in the wrong order. It passes the parent id to the child and the parent id of the parent.

On my routes .rb I have

resources :calendars do
  resources :events
end

which rake routestells me sets up good routes, for example.

calendar_event GET    /calendars/:calendar_id/events/:id(.:format)      {:controller=>"events", :action=>"show"}

Therefore, when I ask you to specify the path for this route from a partial view,

<%= link_to "#{event.name} @ #{event.calendar.name} #{event.calendar.year}", calendar_event_path(event) %>

it gives me a url that has inverted ids ...

http://localhost:3000/calendars/<-eventid->/events/<-calendarid->

Any help would be appreciated.

Edit: in my model, Event belongs_to :calendarand Calendar has_many :events. I also use Mongoid as my ORM and not ActiveRecord, although I hope this is not a problem.

+3
source share
2 answers

URL- URL- calendar_event_path, ( ID) calendar, :

 calendar_event_path(event.calendar, event)

 <%= link_to "#{event.name} @ #{event.calendar.name} #{event.calendar.year}", [event.calendar, event] %>
+6

: id , ? , : id , link_to.

0

All Articles