Getting one of multiple inputs

Say I had many inputs with ids and names in this format: object_#,
where # is any number. Each input is inside its own form with its own
submit button. How can I make the controller get the @params[object_#]?

On Dec 14, 2007, at 4:00 PM, Mike C wrote:

Say I had many inputs with ids and names in this format: object_#,
where # is any number. Each input is inside its own form with its own
submit button. How can I make the controller get the @params
[object_#]?

Assuming the # is in a local variable named my_object

@params[“object_#{my_object}”]

Or, if it is a symbol, then perhaps

@params[“object_#{my_object}”.to_sym]

Something like that should do it.


def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end

Hmm I tried that and it didn’t seem to work…

This thread will help you:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/286f4dbcc6b4c9d0/fbb99b57132e07e9?lnk=st&q=#fbb99b57132e07e9

Something like that should do it.
On Dec 14, 2007, at 10:19 PM, Mike C wrote:

Hmm I tried that and it didn’t seem to work…

Well, this test code works, so it’s just a tweak needed for your
exact names & data types and such.

params = Hash.new

params.store(‘object_1’,‘One’)
params.store(‘object_2’,‘Two’)
params.store(‘object_3’,‘Three’)

my_object = ‘2’

p params[“object_#{my_object}”]

– or with symbols –

params = Hash.new

params.store(:object_1,‘One’)
params.store(:object_2,‘Two’)
params.store(:object_3,‘Three’)

my_object = ‘2’

p params[“object_#{my_object}”.to_sym]


def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs