# Getting values from @params\["variable"\] with a string

**URL:** <https://www.ruby-forum.com/t/getting-values-from-params-variable-with-a-string/61557>\
**Category:** Ruby\
**Created:** [May 25, 2006, 12:29am UTC](https://www.ruby-forum.com/t/getting-values-from-params-variable-with-a-string/61557 "2006-05-25T00:29:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [May 25, 2006, 12:29am UTC](https://www.ruby-forum.com/t/getting-values-from-params-variable-with-a-string/61557/1 "2006-05-25T00:29:28Z")

</div>

I want to retrieve values from params but cannot hardcode in the value  
in the brackets [:value]. I want to be able to have a variable in the  
bracket or a string, but it seems that it doesn’t evaluate what is in  
the brackets.

Any idea of how this can be done

I want to loop through a bunch of column names and store a value from a  
text field of the same name

```
for column in Particular.content_columns
@particular.'column.name'= params[:'column.name']
end

```

However whatever is put between the ’ ’ seems to have to be hard coded?

Suggestions?

Much appreciated

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [May 25, 2006, 12:39am UTC](https://www.ruby-forum.com/t/getting-values-from-params-variable-with-a-string/61557/2 "2006-05-25T00:39:54Z")

</div>

Chris wrote:  
…

> I want to loop through a bunch of column names and store a value from a  
> text field of the same name
> 
> ```
> for column in Particular.content_columns
> @particular.'column.name'= params[:'column.name']
> 
> ```

```
    @particular.send("#{column.name}=", params[column.name.to_sym])

```

> ```
> end
> 
> ```

You may want to cache the “#{column.name}=” strings somewhere so it  
isn’t constructed on each iteration. You could look it up in a hash that  
maps column.name to the appropriate string or symbol.

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [May 25, 2006, 12:55am UTC](https://www.ruby-forum.com/t/getting-values-from-params-variable-with-a-string/61557/3 "2006-05-25T00:55:04Z")

</div>

Beautiful! Thanks Joel
