Reputation: 3923
So I'm trying to follow this: http://web.archive.org/web/20120315004343/http://webtempest.com/sortable-list-in-ruby-on-rails-3-almost-unobtrusive-jquery
And the routing done here is:
resources :books do
post :sort, on: :collection
# ruby 1.8 would go :on => :collection
end
What does post :sort, on: :collection
mean here, and what would be the Rails 4 equivalent?
Upvotes: 0
Views: 54
Reputation: 7921
resources :books
by itself gives you the CRUD routes.
post :sort
by itself gives you a POST
route /sort
to the sort action.
on: :collection
means that the action is for the whole collection (books/sort
), unlike member
which applies to each book (books/:id/sort
). The index
route is a collection route while show
is a member route.
The syntax change from :on => :collection
is exactly the same as on: :collection
when using Ruby 1.9 or greater (as pointed out in the comments). I prefer to use the new syntax because it looks cleaner but it is not required. Both are valid in a Rails 4 app as long as you're using Ruby 1.9 or greater
http://guides.rubyonrails.org/routing.html#adding-collection-routes
Upvotes: 1