Let’s say I have this in a view:
<%= text_field_tag 'foo', params[:foo] %>
Of course this pre-populates the input’s value using the params’ value for ‘foo’. However, I’m using some nesting/arrays for the input names:
<%= text_field_tag 'filters[person][name]' %>
Because params[:filters] and/or params[:filters][:person] may not be present, in order to pre-populate the value, is there a better way to specify the value than the following?
<%= text_field_tag 'filters[person][name]', (params[:filters][:person][:name] if params[:filters] && params[:filters][:person]) %>
This gets messy really fast when more levels are needed. Thanks.
Replace:
With:
Notice you could build some pretty helper based on the
trymethod.