Hi there. I have a conroller, on which I''m using the send() method to find the correct property to assign a posted value to. This looks like so: [code] @charactersheets.send(abl) = v [/code] Where the abl variable is defined earlier, and is a method. And the v variable is a post value assigned earlier. I used to use a switch-case to assign the value, and that worked fine, but this should save time, why does it not work? I get the following error: [code] SyntaxError in CharactersheetsController#show /Users/emil/Sites/ror/dnd/app/controllers/charactersheets_controller.rb:501: syntax error, unexpected ''='', expecting kEND @charactersheets.send(abl) = v ^ RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace Request Parameters: {"name"=>"alexander cavendor"} Show session dump Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} [/code] -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-04 09:28 UTC
Re: The controller.send() method failing to assign value
On 4 Mar 2008, at 08:33, Emil Kampp wrote:> > Hi there. > > I have a conroller, on which I''m using the send() method to find the > correct property to assign a posted value to. This looks like so: > > [code] > @charactersheets.send(abl) = v > [/code] > > Where the abl variable is defined earlier, and is a method. And the v > variable is a post value assigned earlier. I used to use a switch-case > to assign the value, and that worked fine, but this should save time, > why does it not work? I get the following error:because the result of a method call like that isn''t an assignable value. It''s like writing Math.sqrt(4)=3, you just can''t do it. Assuming the variable name is foo, what you need to do is call the foo= method, passing v as the argument. Fred> > > [code] > SyntaxError in CharactersheetsController#show > > /Users/emil/Sites/ror/dnd/app/controllers/ > charactersheets_controller.rb:501: > syntax error, unexpected ''='', expecting kEND > @charactersheets.send(abl) = v > ^ > RAILS_ROOT: ./script/../config/.. > > Application Trace | Framework Trace | Full Trace > Request > > Parameters: {"name"=>"alexander cavendor"} > > Show session dump > > Response > > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > [/code] > -- > 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--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---