Giter Site home page Giter Site logo

nested_form's Introduction

Nested Form

A Rails plugin to conveniently manage multiple nested models in a single form. It does so in an unobtrusive way through jQuery.

This is in early development, so some of this documentation is not yet applicable.

Install

This is currently only available as a plugin.

script/plugin install git://github.com/ryanb/nested_form.git

Usage

When installing this plugin it will add a file at public/javascripts/nested_form.js which should be included after jQuery.

<%= javascript_include_tag 'jquery', 'nested_form' %>

You can then generate a nested form using the nested_form_for helper method.

<% nested_form_for @project do |f| %>

Use this form just like normal, including the fields_for helper method for nesting models. The benefit of this plugin comes from the link_to_add and link_to_remove helper methods on the form builder.

<% f.fields_for :tasks do |task_form| %>
  <%= task_form.text_field :name %>
  <%= task_form.link_to_remove "Remove this task" %>
<% end %>
<%= f.link_to_add "Add a task", :tasks %>

This generates links which dynamically add and remove fields.

Partials

It is often desirable to move the nested fields into a partial to keep things organized. If you don’t supply a block to fields_for it will look for a partial and use that.

<%= f.fields_for :tasks %>

In this case it will look for a partial called “task_fields” and pass the form builder as an f variable to it.

Special Thanks

This plugin is based on the solution by Tim Riley in his complex-form-examples fork.

github.com/timriley/complex-form-examples/tree/unobtrusive-jquery-deep-fix2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.