I have this method that it''s soul purpose is to toggle a field and then redisplay a chech_box helper and a image signifying that the field has been updated. My issue, however, is that this method is to toggle several different field all via one method simply because the code to do so was all the same code save for the name of the field. I pass a value in which is the name of the field that I am manipulating, for example: def method_1(attribute_name) ..... end In that method I find a user based on an id and then I need to set an attribute based on the value passed in, so I have: @user.find_by_id(params[:id]) @user."#{attribute_name}" However, that last bit of code doesn''t work. Is there a way to do what I am trying to do, that is, use dot notion on an object to update a field whose value is being passed into the method? Thanks in advance, -S -- 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 -~----------~----~----~----~------~----~------~--~---
try to do @user[attribute_name] = value if you pass a string or a symbol =] -- 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 -~----------~----~----~----~------~----~------~--~---
On 9 Sep 2008, at 18:25, Shandy Nantz wrote:> > @user."#{attribute_name}" > > However, that last bit of code doesn''t work. Is there a way to do > what I > am trying to do, that is, use dot notion on an object to update a > field > whose value is being passed into the method? Thanks in advance, >You can use send to call methods by name. Fred> -S > -- > 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 -~----------~----~----~----~------~----~------~--~---
Fabio Eidi wrote:> try to do > > @user[attribute_name] = value > > if you pass a string or a symbol =]That did the trick. Thx, -S -- 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 -~----------~----~----~----~------~----~------~--~---