-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME
More file actions
50 lines (32 loc) · 1.37 KB
/
README
File metadata and controls
50 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
= 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]>