문제

Consider this:

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

However, if we now have the arguments in an array: [:phone, {class: "input span2", id: "follow_up_phone"}]

How would I call text_field_tag using that array?

text_field_tag array

doesn't seem to work

도움이 되었습니까?

해결책

First of all: where's your value? The signature is:

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

So, you have to call it this way:

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

And your array has to be:

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

Use splat operator to pass this array:

text_field_tag *array

다른 팁

I believe :phone[] will work. For example, I've done this before in a form:

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

where the parameter is an array of question ids.

Hope that works!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top