formnestic

An extension of famous Formtastic Form Builder to make building nested and association form with nested model addable and removable ability extremely easy and simple.

Checkout the the Demo

Compatibility

Installation

Add Formnestic to your Gemfile and run bundle install:

gem "formnestic", '~> 1.0.2'

then run the installation

bundle exec rails g formnestic:install

Features

Usage

Usage for rails 3 and rails 4 are almost the same, the only difference is that in Rails 4, you will need to remove all the attr_accessible in Rails 3 and use strong parameters in rails controller.

Basically, you can now add the following options into semantic_fields_for call in Formtastic

[
  [{label: 'Column 1', wrapper_html: {class: "big-column"}}, {label: 'Column 2'}],
  [{attr: :name}, {attr: :description}],
]

will yield a table header with 2 rows. The first row has 2 columns labeled Column 1 and Column 2 respectively, the second row labelled respected attribute's name of the nested model.

The form view is the same between Rails 3 and Rails 4

<%= semantic_form_for @quiz_pool do |quiz_pool_form| %>
  <%= quiz_pool_form.inputs do %>
    <%= quiz_pool_form.input :title %>
    <%= quiz_pool_form.input :description %>
    <li>
      <%= quiz_pool_form.semantic_fields_for :quiz_pool_questions, {
        row_removable: true, 
        row_addable: true,
        min_entry: 1, 
        max_entry: 5,
        new_record_link_label: "+ question"
      } do |quiz_pool_question_builder| %>
        <%= quiz_pool_question_builder.inputs do %>
          <%= quiz_pool_question_builder.input :description %>
          <%= quiz_pool_question_builder.input :score %>
        <% end %>
      <% end %>
    </li>
  <% end %>
  <%= quiz_pool_form.submit %>
<% end %>

See the usage for each of Rails version below for more details

Rails 3 Usage

Rails 4 Usage

Screenshots

Table Form

Table Form

List Form

List Form

Roadmap to version 2.0

Contributing to formnestic

Credits

Copyright © 2014 James, released under the MIT license