Hi all, I am learning how to think RESTfully and in my quest for improvement I need help with the issue I am facing. I have a RESTful model "User" and I want to add a link on the listing (index) page that is a one-click to disable/enable that user i.e. simply toggle the active column to the correct value. Since I am just updating a column in the object it seemed to me that this should be a simple PUT request with the correct value for the column (true/false). However, I can''t figure out how I can add the value of "active" to the request using a link_to and the REST routes helper methods. <%= link_to ''Disable'', user_path(user), :method => :put %> Is as far as I have been able to get. I did try changing the url to use the raw hash but that didn''t work either. Could someone please give me some direction on this? Oh yeah, I do realize I could create a new member route for this, but somehow it doesn''t seem "correct" considering it should just be a simple Update operation. Thanks Peer -- 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Peer Allan wrote:> Hi all, > > I am learning how to think RESTfully and in my quest for improvement I > need help with the issue I am facing. > > I have a RESTful model "User" and I want to add a link on the listing > (index) page that is a one-click to disable/enable that user i.e. simply > toggle the active column to the correct value. Since I am just updating > a column in the object it seemed to me that this should be a simple PUT > request with the correct value for the column (true/false). However, I > can''t figure out how I can add the value of "active" to the request > using a link_to and the REST routes helper methods. > > <%= link_to ''Disable'', user_path(user), :method => :put %> > > Is as far as I have been able to get. I did try changing the url to use > the raw hash but that didn''t work either. Could someone please give me > some direction on this? > > Oh yeah, I do realize I could create a new member route for this, but > somehow it doesn''t seem "correct" considering it should just be a simple > Update operation. > > Thanks > > PeerTry: <%= link_to ''Disable'', user_path(:id => user.id, :active => false), :method => :put %> Yeah, it''s ugly, but it should work. I had a similar problem, and had to resort to this as well. If someone knows a better solution, please let me know :) -- 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Thanks for the response, but unfortunately that did not work. I looked at the javascript generated by and there is no reference of the "active" field and naturally it is not part of the params when I submit. Peer Gerjan Stokkink wrote:> > Try: > > <%= link_to ''Disable'', user_path(:id => user.id, :active => false), > :method => :put %> > > Yeah, it''s ugly, but it should work. I had a similar problem, and had to > resort to this as well. If someone knows a better solution, please let > me know :)-- 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---