Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

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!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top