I have a column in my table that is an integer. I'm trying to make a link in my application that puts a specific integer in that column.
i.e. :
User clicks link labeled 0 => record in DB sets record to 0
User clicks link labeled 1 => record in DB sets record to 1
ETC. . .
In the VIEW:
<%= link_to "0",
{:controller => "application",
:action => 'rate_app'},
:class => "rate_btn",
:method=> :put
%>
In the CONTROLLER:
def rate_app(current_user, rating)
current_user.nps_rating = rating
if current_user.save
redirect_to mypage_path
end
end
Does anyone see开发者_C百科 a conflict/mess-up in the code? I get an error.
If you are adding information to your db, it should be done via a POST. Links are a GET. With that being said, I would suggest looking at button_to to solve this one.
http://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to
精彩评论