lundi 30 mars 2015

Pass multiple params to the current page with form_tag in Rails

I want to pass several params in the url of the current page with a form_tag but I have failed to understand to correct syntax.



Quick explanation: I have outfits (model) that has many outfit_items (model).

Each outfit_item has available_sizes (attribute of outfit_item). All of this is set by the admin.



Then on the show page of an Outfit, (for example http://localhost:3000/outfits/7) I want to display the available sizes for each outfit_item, let the visitor pick his size for each item and press submit. The selected sizes should then appear in the URL. Here is what I have in my show view, at the url :



<%= form_tag(@outfit_path, :method=>'post') do %>
<% @outfit.outfit_items.each do |outfit_item| %>
<div class="col-md-2 col-sm-6 col-xs-6">
<%= image_tag outfit_item.item_image.url(:medium) %><br>
<% sizes = outfit_item.available_sizes.split(",") %>
<%= select_tag "size#{outfit_item.category}", "<option>#{sizes[1]}</option><option>#{sizes[2]}</option><option>#{sizes[3]}</option><option>#{sizes[4]}</option>".html_safe, :class => "input-mini select-mini" %><br>
<%= hidden_field_tag "size#{outfit_item.category}", value: outfit_item.category %>
</div>
<% end %>
<%= submit_tag "ok size" %>
<% end %>


I want to land on this url when I hit submit



http://localhost:3000/outfits/7?size1=42&size2=L&size3=S&size4=44


Thanks for your help


Aucun commentaire:

Enregistrer un commentaire