如何用数组调用text_field_tag?

时间:2013-05-13 17:09:47

标签: ruby-on-rails ruby forms helpers

考虑一下:

text_field_tag :phone, :class => "input span2", :id=>"follow_up_phone"

但是,如果我们现在在数组中有参数:[:phone, {class: "input span2", id: "follow_up_phone"}]

如何使用该数组调用text_field_tag?

text_field_tag array

似乎不起作用

2 个答案:

答案 0 :(得分:4)

首先:你的价值在哪里?签名是:

text_field_tag(name, value = nil, options = {})

所以,你必须这样称呼它:

text_field_tag :phone, nil, :class => "input span2", :id=>"follow_up_phone"
                        ^

您的array必须是:

[:phone, nil, {class: "input span2", id: "follow_up_phone"}]

使用splat运算符传递此数组:

text_field_tag *array

答案 1 :(得分:0)

我相信:phone[]会奏效。例如,我之前以一种形式完成了这个:

<input type="checkbox" name="question_id[]" value=<%= q.id %>>

其中参数是问题ID的数组。

希望有效!