Gandalf Graubart
2010-Oct-15 13:39 UTC
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 ;) 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! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2010-Oct-15 13:48 UTC
Re: Changing one item in database without invoking another view than index
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 On Oct 15, 2010, at 9:39 AM, Gandalf Graubart wrote:> Hi, > > I am new to rails, well, sure you will notice that given my > question ;) > > 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! > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.