Giter VIP home page Giter VIP logo

multimodel-forms's Introduction

= Multimodel-Forms

This plugin allows multiple models to have a place in one form. For example, if an article model has_many links. The links can be edited, created, deleted and even sorted (acts_as_list) from the article edit/new form. Included ajax helpers so links can be added and deleted client side and db is only touched when form is submitted.

This is largely derived from Ryan Bates' tutorial over at: http://railscasts.com/episodes/75

Acquire via git at: git clone [email protected]:sudothinker/multimodel-forms.git
  
Sample project available in multimodel-forms/sample_project - This can be removed if not needed.

== Example

  article.rb

  class Article < ActiveRecord::Base
    has_many_with_attributes :links
  end

  --
  link.rb

  class Link < ActiveRecord::Base
    belongs_to :article
  end

  Can now add a view partial to render the article form and edit the associated links.

  articles/_form.rhtml

  <label>Title</label>
  <%= f.text_field :title %>

  <h3>Links</h3>
  <div id="links">
    <%= render :partial => 'links/link', :collection => @article.links %>
  </div>

  <%= add_link "Add link", :link %>

  links/_link.rhtml

  <p class="link">
  <% fields_for_associated :article, link do |l_form| %>
    <%= l_form.text_field :url, :index => nil %>
    <%= delete_link_for(link, "Delete", l_form) %>
  <% end %>
  </p>


Written by Michael Murray <[email protected]>

multimodel-forms's People

Contributors

lucasefe avatar sudothinker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ramonrails

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.