jquery - Railscast 197, part 2: How to remove a group of fields in Rails 3? -


i'm constructing form in rails 3, following instructions in video: http://railscasts.com/episodes/197-nested-model-form-part-2.

my form has 1 major difference form in video: instead of being able remove 1 field on form, i'd able remove group of fields form. group contains following fields: "number of people", "gender", "ethnicity", "age". able remove group of fields using checkbox in part 1 of video series, since added jquery functionality, hasn't worked.

any suggestions?

new.html.erb

<%= f.fields_for :audiences |builder| %> <div class="audiencefields">  <%= builder.hidden_field :_destroy %> <%= link_to_function "remove", "remove_fields(this)" %> <p>     <%= builder.label :number_of_people %><br />     <%= builder.text_field :number_of_people %> </p> <p>     <%= builder.label :gender %><br />     <%= builder.text_field :gender %> </p> <p>     <%= builder.label :ethnicity %><br />     <%= builder.text_field :ethnicity %> </p> <p>     <%= builder.label :age %><br />     <%= builder.text_field :age %> </p> </div> <% end %> 

application.js

function remove_fields (link) {         $(link).previous("input[type=hidden]").value = "1";         $(link).up(".audiencefields").hide();     }     

i spent while trying figure out, couldn't find solution since railscast seems out of date rails 3. ended installing nested form gem, , works beautifully: https://github.com/ryanb/nested_form


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -