Changing one item in database without invoking another view than index

Hi,

I am new to rails, well, sure you will notice that given my question :wink:

Starting from a simple application for demonstration, just one table
with name, status and all the generated scaffold around. Index page with
the links to new/edit/delete and all the rest. I do understand the way
edit and new works, with their own views and the methods in the
controller.
Let’s say, I want to add one link(_to) to each line in the index view,
call it change_status. On click a method in the controller should change
the corresponding item (id) and set to status to a new value, then
reload the index page. As I expect without invoking any other view but I
do not manage to tell rails about…

I would really appreciate, if one of you could give me a hint (e.g. what
to search for in documentations/tutorials, I am using Rails3).

Thanks in advance!

Off the top of my head, you could do this:

  1. Make a new controller method that changes status.
  2. Include whatever checks you need for the authority to make this
    change (is the change being made to the current user, or does the
    current user have the privilege to change another user).
  3. At the end of a save, successful or not, set the flash and then
    redirect back to index.
  4. Update your routes to include a path to this new method.

I’ve done this to allow an admin to change a user’s role (in Rails
2.3.8):

def set_role
@user = User.find(params[:id])
if @user.update_attribute(:role, params[:role])
flash[:notice] = “Successfully updated role.”
end
redirect_to(users_path)
end

Walter