开发者

Why do hidden fields produce hashes?

开发者 https://www.devze.com 2023-02-10 03:35 出处:网络
My Hidden Field: - @calc.results.each do |k, v| = hidden_field :calc开发者_开发技巧_result, :value => \"#{k[:total_interest]}\"

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"


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.


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]}
0

精彩评论

暂无评论...
验证码 换一张
取 消