Вопрос

I have the following nested resources in my rails 3 app.

resources :calendars do
  resources :events
end

What is the recommended url/path for displaying (list or calendar) events for a specific calendar? Should I use the show method of the calendar controller (http://mydomain.com/calendars/1), or the index method of the events controller (http://mydomain.com/calendars/1/events)? Is it a matter of personal preference, or are there conventions/best practices for handling this situation?

Thanks!

Это было полезно?

Решение

The convention in standard RESTful apps would be to use http://mydomain.com/calendars/1/events, since events in your example are a nested resource. That is, the calendar resource has many events resources.

That being said, if you were actually displaying a visual calendar (that happened to have events populated on it), you'd go with http://mydomain.com/calendars/1, since the main resource you're displaying is the actual calendar.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top