Forum: Ruby Getting values from @params["variable"] with a string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris (Guest)
on 2006-05-25 02:29
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
Joel VanderWerf (Guest)
on 2006-05-25 02:39
(Received via mailing list)
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.
Chris (Guest)
on 2006-05-25 02:55
Beautiful! Thanks Joel
This topic is locked and can not be replied to.