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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request