I want to create a hidden field and create a link in one helper and then output both to my erb.
<%= my_cool_helper 'something', form %>
Should out put the results of
link_to 'something', a_path form.hidden_field 'something'.tableize, :value => 'something'
What would the definition of the helper look like? The details of what link_to and the form.hidden_field don’t really matter. What matters is, how do I return the output from two different calls.
There are several ways to do this.
Remember that the existing rails helpers like
link_to, etc, just output strings. You can concatenate the strings together and return that (which is what I do most of the time, if things are simple).EG:
If you’re doing things which are more complicated, you could just put that code in a partial, and have your helper call
render :partial.If you’re doing more complicated stuff than even that, then you may want to look at errtheblog’s block_to_partial helper, which is pretty cool