Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing custom action in Rails 3

I have a very simple question. Trying to figure out what is the simplest way to route the custom action in rails 3.

Let's say i have controller UsersController and action promote_to_premium

Nor

http://localhost:3000/users/#{user_id}/promote_to_premium  

neither

http://localhost:3000/users/promote_to_premium/#{user_id}

works.

Should I specify in routes.rb every custom action that differs from new/delete/update/create/ect/....?????

Thank You.

like image 372
Benjamin Harel Avatar asked Nov 28 '22 09:11

Benjamin Harel


1 Answers

Yes you need to specify in your routes.rb.
Example:

resources :users do
  member do
    post :promote_to_premium
  end
end

This way you can access the route like this:

http://localhost:3000/users/#{user_id}/promote_to_premium
like image 77
MurifoX Avatar answered Nov 30 '22 22:11

MurifoX