Reputation: 47
I'm creating a specific helper for my page using the rails form_tag
helper. Here is my code:
def horta_form(form, args = {})
set_editable(form) unless args[:editable] == false
identifier, send_to, classes, style = form.identifier, form.send_to, form.classes, form.style
form_tag("/contact", method: "post") do
text_field_tag('name')
text_field_tag('email')
text_area_tag('message')
submit_tag('Send')
end
end
But in my view, it only renders the last tag, the submit_tag
.
<%= horta_form(@form) %>
returns
<form action="/contact" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="authenticity_token" value="/WLo9GzhGdD7dBk3Eh8k4Q/+jQ0r+EGqgoOXBedyl/NW6g5gBQ/R4U4gFEtXmz1xJlISHAYykZRkmDHhQJm8uQ==">
<input type="submit" name="commit" value="Send" data-disable-with="Send">
</form>
What should I do to make the horta_form
return the form with all inputs, not just the last one?
Upvotes: 1
Views: 112
Reputation: 106882
Use concat
when you need nested structure in your helpers:
def horta_form(form, args = {})
#...
form_tag("/contact", method: "post") do
concat text_field_tag('name')
concat text_field_tag('email')
concat text_area_tag('message')
concat submit_tag('Send')
end
end
Upvotes: 1