views:

239

answers:

1

In the controller, how can I add a variable at the end of a params[]?

If I try this I get an error: params[:group_] + variable

How should it be done?


Edit per request

Ok, I have a form that sets groups of radio buttons with names like this:

group_01DRN0

Obviously I have different groups in the form (group_01AAI0, group_01AUI0, etc.) and the value is set according to the radio button selected within the group:

Radio button "group_01DRN0" could have value of "21" or "22" or "23", radio button "group_01AAI0" could have value of "21" or "22" or "23", etc.

In the DB I have every code (01DRN0, 01AAI0, 01AUI0, etc) so I want to select them from DB and iterate in the params value so I can get the radio button group value, I've tried this with no luck:

@codes=Code.get_codes
for c in @codes
  @all=params[:group_] + c.name
end

Thanks.

+1  A: 

params looks like a hash, but it really isn't. So if you need to "augment" params as you deal with the incoming data in your controller, invent a new data structure that includes either params or its members.

Added:

Maybe you're looking for

@codes=Code.get_codes
@all = []    
for c in @codes
  @all << params["group_#{c.name}"]
end
Larry K
I did not know you could use "group_#{c.name}" inside params[]! But that did the trick, thanks!
miligraf