No commit activity in last 3 years
No release in over 3 years
Dynamically add and remove form fields in a Rails 3.1+ app
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

JqueryDynamicFields

Most of code pulled from Railscasts 196 (revised)

WIP: very alpha bro

Compatibility

  • = Rails 3.1

  • = Ruby 1.9.2

Installation

Add this line to your application's Gemfile:

gem 'jquery_dynamic_fields'

And then execute:

$ bundle

In your pipeline

// in app/assets/javascripts/application.js
//= require jquery_dynamic_fields

How to use

class TaskList < ActiveRecord::Base
  has_many :tasks
  accepts_nested_attributes_for :tasks
end

class Task < ActiveRecord::Base
  belongs_to :task_list
end
<%# app/views/task_list %>

<%= form_for @task_list do |f| %>
  <%= link_to_add_fields "Add a task", f, :tasks %>
  <%= f.submit "Save!" %>
<% end %>

<%# the partial name must match (relation singular)_fields so in this case "task"
    and be in the same directory as the template calling #link_to_add_fields %>

<%# app/views/task_list/_task_fields.html.erb %>
<fieldset>
  <%= f.text_field :label %>
  <%= link_to_delete_field f %>
</fieldset>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request