¿Cuál es la diferencia lógica entre resource
y resources
métodosdiferencia entre los métodos de recursos y recursos
Aquí está algunos ejemplos:
resource :orders, :only => [:index, :create, :show]
> rake routes
orders POST /orders(.:format) orders#create
GET /orders(.:format) orders#show
resources :orders, :only => [:index, :create, :show]
> rake routes
orders GET /orders(.:format) orders#index
POST /orders(.:format) orders#create
order GET /orders/:id(.:format) orders#show
resource :orders
> rake routes
orders POST /orders(.:format) orders#create
new_orders GET /orders/new(.:format) orders#new
edit_orders GET /orders/edit(.:format) orders#edit
GET /orders(.:format) orders#show
PUT /orders(.:format) orders#update
DELETE /orders(.:format) orders#destroy
resources :orders
> rake routes
orders GET /orders(.:format) orders#index
POST /orders(.:format) orders#create
new_order GET /orders/new(.:format) orders#new
edit_order GET /orders/:id/edit(.:format) orders#edit
order GET /orders/:id(.:format) orders#show
PUT /orders/:id(.:format) orders#update
DELETE /orders/:id(.:format) orders#destroy
Parece método resource
no crea ruta para index
y ayudantes de algunos casos son diferentes (new_order y new_orders). ¿Por qué?
Creo que te refieres a la primera línea para decir 'resource: orders,: only ...' – mmcrae
"Los ayudantes también deberían diferir": significa que obtienes 'new_order_path' for' resources' y 'new_orders_path' for' resource '. – Adobe
La principal diferencia no es solo la página de índice. - ** resources ** creará rutas con página de índice y también requerirá: parámetro id para editar, actualizar, destruir y mostrar acciones ([Check] http://guides.rubyonrails.org/routing.html#specifying -a-controller-to-use) - ** resource ** creará las mismas rutas sin ruta de índice y sin necesidad: id param. ([Comprobar] http://guides.rubyonrails.org/routing.html#singular-resources) – stopanko