jquery - Pass hidden field in rails -


i have table tours (and table toursights allows multiple sights single tour). in new/create form, i'm trying add multiple sights tour. way i've done using jquery, "joined" values of input forms single string of sights , set value of single hidden field. i'm lost how expand once hits model , add each 1 table. ideas?

tour.js

  $("#new_tour").on("submit", function(event){      event.preventdefault();      var inputs = $.map($(".sight_field"), function(input_element){         return input_element.value;      });      var inputs_joined = inputs.join("|");      $(":hidden").val(inputs_joined); });  

portion of index.html.erb

<div class="input_fields_wrap">    <button class="add_field_button">add more sights</button>       <%= f.label :sights %>     <input type="text" class="sight_field"> </div> <div>    <%= f.hidden_field :sights %> </div> 

with rails don't need such things.

create proper form around fields , let submit. within controller variables in params-hash. e.g.

params[:sights] 

if gets complicated, can have things like

<input type="hidden" name="seeing[paris][sight]" value="fine" /> <input type="hidden" name="seeing[munich][sight]" value="fantastic" /> 

which result in controller

params[:seeing][:paris][:sight] params[:seeing][:munich][:sight] 

if reason not feasible, can this:

<input type="hidden" name="sights" value="fine, fantastic, ok" /> 

and in controller

all_sights = params[:sights].split(',') 

which array of sights.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -