I just wanted to know if there is any method available to update a record of a table from a view? For example am I able to delete a record from the table using the code below?
<td><%= link_to 'Delete', my_path(user), :confirm => 'Are you sure?', :method =>:delete, :remote=>true %></td>
And in my controller I have:
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.js do
render(:update) { |page| page.reload }
end
end
end
The above code works perfectly. It deletes the record from the table and also reloads the page after clicking the destroy link. Now, my question is: can I do the same for updating a value in my record? If so, how can I do that?
Sure you can, you would simply change a few things:
The method in your controller would be update:
Then you would change your link to something like the following:
Mind you, this is under the presumption that you are in a
form_for @usertag.This is under the impression that you setup @user in the controller method (most likely
def edit)