[ACCEPTED]-Ruby on Rails link_to With put Method-link-to

Accepted answer
Score: 40

Updated - The link_to helper will do a GET unless a method 5 is specified.

Its better specifying the exact 4 request type, instead of match in your routes 3 file. How about replacing match by put in routes 2 as :

put '/admin/users/:id/activate' => 'admins#activate_user', :as => 'activate_user'

link_to 'Activate', activate_user_path(user.id), method: :put

The activate_user method should reside in admins controller. The 1 docs has more info on link_to helper.

Score: 32

link_to thinks that :method => :put is part of the path hash. You 7 have to tell it otherwise. Wrap your path 6 in brackets.

link_to 'Activate', {:action => :activate_user, :id => user.id}, :method => :put

Now link_to will recognize :method => :put as an option, not 5 part of the link's path.

As a side note, you 4 should try to use route helpers instead 3 of path hashes whenever possible. Keeps 2 things nice and tidy, and avoids nit-picky 1 situations like this.

Score: 0

If You are using link_to do then you can use the 1 following syntax

<%= link_to admin_subscription_path(user), method: :put do %>
 # can put html & css here
<% end %>

More Related questions