I want to ask how to directly update a single attribute in rails. I've already tried many ways to solve it but none of them works. Currently, in my view I have this line of code:
<%= link_to("Ban", admin_update_path(user), :confirm => "Are you sure?")%>
Then in my controller:
def update
@user = User.first
if @user.update_attributes(:reputation =>1)
redirect_to admin_viewAllUsers_path, :notice => "User banned!"
else
render "index"
end
end
Then in my routes:
get "admin/edit"
put "admin/update"
Note: If I used put "admin/update" in my routes, I would get "No route matches [GET] "/admin/update.2" error, but when I used get "admin/update" I didn't get any error but my :reputation wouldn't update. Btw, :reputation is an integer
Moreover, If I use User.find(params[:id]) instead of User.first, I'll get "Couldn't find User without an ID" error.
Pls help. What should I do? Where did I go wrong?
#update_attributes. try adding a debug line before therender 'index'line