Wierd form_for behavior
Closed this issue · 4 comments
Before I start -- is there a Google group or something for this? I'm not sure this is an issue...
In my presenter I have this:
def welcome_form(obj, field, text_label)
form_for obj do |f|
f.label field, text_label, :class => "form-description"
f.text_field field
f.submit "Submit"
end
end
If I put the same type of thing directly into the template it works. If I put it in the presenter, the form and submit render but the label and text field do not.
I don't want to use the rumble interface for various reasons.
Before, I had the _tag versions (i.e. form_tag, label_tag, etc) and had exactly the same issue.
This would be true in a helper too. When you do <%= f.label etc %>
in a template, you're telling ERB to insert the return value of that method call. In this case, you're just throwing the return values of the first two method calls away.
Probably the best non-Rumble way to deal with this is something like
form_for obj do |f|
f.label(field, text_label, :class => "form-description") +
f.text_field(field) +
f.submit("Submit")
end
or
form_for obj do |f|
out = f.label field, text_label, :class => "form-description"
out << f.text_field field
out << f.submit "Submit"
end
or use join
and html_safe
, or use a partial and render it from the helper.
Let me know if you have any more questions. There isn't a Google Group, but I think issues are fine for this kind of thing.
Ok Thanks.
It use to be that there was "binding" that you had to play with properly. IIRC binding.concat "whatever"
but they got away from that. Now, some tags magically work and other things don't.
I guess... what I don't get the most is why submit works.
Thank you again...
Perry
On Dec 17, 2012, at 5:00 PM, Ryan Fitzgerald wrote:
This would be true in a helper too. When you do <%= f.label etc %> in a template, you're telling ERB to insert the return value of that method call. In this case, you're just throwing the return values of the first two method calls away.
Probably the best non-Rumble way to deal with this is something like
form_for obj do |f|
f.label(field, text_label, :class => "form-description") +
f.text_field(field) +
f.submit("Submit")
end
orform_for obj do |f|
out = f.label field, text_label, :class => "form-description"
out << f.text_field field
out << f.submit "Submit"
end
or use join and html_safe, or use a partial and render it from the helper.Let me know if you have any more questions. There isn't a Google Group, but I think issues are fine for this kind of thing.
—
Reply to this email directly or view it on GitHub.
I got it! Dahh...
submit was rendered not because it was special but because it was the last thing in the block so it was the value that the block returned...
I had the same issue with link_to
. Had to wrap it into a text(...)
call or it wouldn't be rendered. Maybe this can be improved somehow?