Why do hidden fields produce hashes?

247 Views Asked by At

My Hidden Field:

- @calc.results.each do |k, v|
  = hidden_field :calc_result, :value => "#{k[:total_interest]}"

Which returns :

"calc_result"=>
{"value214.14"=>"",
...

How can I write the hidden_field so that it produces :

"value" => "214.14"
2

There are 2 best solutions below

2
On BEST ANSWER

You don't need to pass :value, just say this:

= hidden_field_tag :calc_result, "#{k[:total_interest]}"

That should get you what you want.

0
On

By using hidden_field, the name attribute is interpreted from the field name (in this case :calc_result.

If value is not a field in the model, you could use hidden_field_tag instead.

= hidden_field_tag "value", k[:total_interest]}