# The controller.send() method failing to assign value

**URL:** <https://www.ruby-forum.com/t/the-controller-send-method-failing-to-assign-value/130892>\
**Category:** Rails\
**Created:** [March 4, 2008, 9:33am UTC](https://www.ruby-forum.com/t/the-controller-send-method-failing-to-assign-value/130892 "2008-03-04T09:33:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [March 4, 2008, 9:33am UTC](https://www.ruby-forum.com/t/the-controller-send-method-failing-to-assign-value/130892/1 "2008-03-04T09:33:48Z")

</div>

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:

```auto
@charactersheets.send(abl) = v
```

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:

```auto
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"}
```

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [March 4, 2008, 10:29am UTC](https://www.ruby-forum.com/t/the-controller-send-method-failing-to-assign-value/130892/2 "2008-03-04T10:29:36Z")

</div>

On 4 Mar 2008, at 08:33, Emil K. wrote:

> 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
