I’m having a form where the user can select the line items that he wants
to create. All line items are new and don’t have an id.
I realized that check_box created a hidden field that’s supposed to help
me, but it doesn’t work when I receive the params[:line_items]. I get a
double number of line items. I can fix it in the controller, but it’s
just ugly. Advices?
<%fields_for ‘line_items[]’, li do |l|%>
<%=l.check_box :selected_for_save%> <%=l.hidden_field
:container_id%>
<%=l.hidden_field :amount%>
<%end%>
On Aug 4, 9:42 pm, Constantin G. <rails-mailing-l…@andreas- s.net> wrote:
<%=check_box_tag ‘line_items[][selected_for_save]’ %>
instead of
<%=l.check_box :selected_for_save%>
I find it ugly. I don’t want to mix formhelpers with formtaghelpers.
It’s kludgy but right now it’s the only way if line_items is to be an
array parameter. The way that the form parameter parser detects that a
new array element is starting is when it spots a repeated parameter
name.
If you make line_items a hash parameter you won’t have this problem,
ie generate inputs