Hidden fields params

Ok, I’m working dilegently on my question from yesterday and I will post
the answer once I get one working… but I’m having problems on an
interim stage.

Hidden field basics…I really wrestle getting things in and out of
parameters from view to controller so I’m trying this simple approach.

<% for person in @people %>
<% [Santa, Elf, Reindeer].each do |holiday_character| %>

<% form_tag :action => :manipulate_based_on_input do %> If you click the button below this person : <% image_tag (peron.photo_url) %> will be tranformed into a<%=h holiday_character %>
  <%= hidden_field( :holder1, :value => person.id )%>

  <%= hidden_field( :holder2, :value => holiday_character ) %>
  <% submit_tag "click here" %>
 <% end %>
<% end %> <% end %>

Ok hopefully I didnt make any typos above because it isnt my exact code
thats on a different machine.

MY problem is that the params from the hidden fields look strange.

If I force an error to look at my params I get something like:

{ “commit”=>“click here”, “holder1” =>{“value166”=>""}, “holder1”
=>{“valueSanta”=>""} }

what I want (I think) is more like {. … , “holder1” => “166”, “holder2”
=> “Santa” }

If I instead use a hidden_ield like:
<%= hidden_field( :holder2, holiday_character ) %>
my params look more like {… , “holder2”=>{“Santa”=>""}, …}

Can I get a simple params like “holder2”=>“Santa” .??

If not which of the two alternatives should I use and how do I access
the info in the params?

?? params[:holder2][value] ?? (will it work even with the “value166”=""
subhash?)

you’re using hidden_field as though you are using hidden_field_tag.

You need to specify an object for the hidden_field tag or switch over to
hidden_field_tag.

<%= hidden_field_tag ‘test’, ‘value’ %>

Will give you params[:test] as “value”

On Dec 17, 2007 1:23 PM, Tom N. [email protected]
wrote:

{ "commit"=>"click here", "holder1" =>{"value166"=>""}, "holder1"

If not which of the two alternatives should I use and how do I access
the info in the params?

?? params[:holder2][value] ?? (will it work even with the “value166”=“”
subhash?)

Posted via http://www.ruby-forum.com/.


Ryan B.

On 17 Dec 2007, at 02:53, Tom N. wrote:

<% [Santa, Elf, Reindeer].each do |holiday_character| %>
<% end %>

<% end %> <% end %>

Ok hopefully I didnt make any typos above because it isnt my exact
code
thats on a different machine.

That’s really unhelpful. If you are going to post code, post exactly
what you are using. Often enough, the devil is in the detail. As it is
people have to guess whether what looks like a mistake is a mistake or
just a typo.

MY problem is that the params from the hidden fields look strange.

If I force an error to look at my params I get something like:

{ “commit”=>“click here”, “holder1” =>{“value166”=>""}, “holder1”
=>{“valueSanta”=>""} }

Check the docs for hidden_field_tag (I’m assuming that’s what you
actually meant, rather than what you’ve remembered). The second
parameter is the value, but you’re passing :value => foo.

what I want (I think) is more like {. … , “holder1” => “166”,
“holder2”
=> “Santa” }

If I instead use a hidden_ield like:
<%= hidden_field( :holder2, holiday_character ) %>
my params look more like {… , “holder2”=>{“Santa”=>""}, …}

Can I get a simple params like “holder2”=>“Santa” .??

According to your code above, Santa is a class/module. You want to be
passing an actual string to hidden field.

Fred

On Mon, 2007-12-17 at 03:53 +0100, Tom N. wrote:

<% form_tag :action => :manipulate_based_on_input do %>
<% end %>
=>{“valueSanta”=>""} }
If not which of the two alternatives should I use and how do I access
the info in the params?

?? params[:holder2][value] ?? (will it work even with the “value166”=""
subhash?)


<%= hidden_field ‘holder2’, :value => “Santa” %>
<%= hidden_field ‘holder1’, :value => person.id %>

Craig

Ryan B. wrote:

you’re using hidden_field as though you are using hidden_field_tag.

You need to specify an object for the hidden_field tag or switch over to
hidden_field_tag.

Thanks a bunch Ryan, the hidden_field_tag did the trick!

Fred,

MY home office in the garage got too cold to work in and the machine
with rails and the code on it is sitting out of reach of a cable! (I do
hear your point about the devil being in your details and I will need to
scratch my head about that as I certainly want to do everything I can to
be couteous to people so generously helping).

It does look like I made an error with my example of the character array
…for it to be a string, not a class/module the array should have been
[“Santa”, “Elf”, “Reindeer”] (with the quotes). I apoligize that my
typing stuff in out of my head instead of from something i tested let
that through.

Thanks for the help on this and the pointers for the clickable divs last
night… I’ve almost got yesterday’s question worked out now.

On 17 Dec 2007, at 03:05, Frederick C. wrote:

Check the docs for hidden_field_tag (I’m assuming that’s what you
actually meant, rather than what you’ve remembered). The second
parameter is the value, but you’re passing :value => foo.

Meant to add: if you do mean hidden_field, then you need to say
hidden_field instance_variable_name, method, :value => ‘foo’

Fred

You may have fixed this by now, but for anyone else. it’s
hidden_field_tag.

Matt