Created
June 8, 2010 16:20
-
-
Save chrislerum/430257 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Branch < ActiveRecord::Base | |
belongs_to :tree | |
has_many :leaves | |
validates_presence_of :name, :message => "A branch without a name? WTF?" | |
validates_presence_of :tree_id, :message => "was not there dude." | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parameters: {"commit"=>"Save changes", "authenticity_token"=>"YnGd4rKBCki4+r6sNcwfDlgR5Ur+O7emsQZkGvJu/zw=", "tree"=>{"name"=>"Hank the Tree", "branches_attributes"=>{"0"=>{"name"=>"Bob the Branch"}}}} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New Tree | |
<br /> | |
<% form_for setup_tree(@tree) do |tree_form| %> | |
<%= tree_form.error_messages %> | |
<%= tree_form.label :name, "Tree Name:" %> | |
<%= tree_form.text_field :name %> | |
<br /><br /> | |
Add a branch: | |
<br /> | |
<% tree_form.fields_for :branches do |branch_form| %> | |
<%= branch_form.label :name, "Branch Name:" %> | |
<%= branch_form.text_field :name %> | |
<% end %> | |
<br /> | |
<%= tree_form.submit %> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="/trees" class="new_tree" id="new_tree" method="post"><div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="YnGd4rKBCki4+r6sNcwfDlgR5Ur+O7emsQZkGvJu/zw=" /></div> | |
<label for="tree_name">Tree Name:</label> | |
<input id="tree_name" name="tree[name]" size="30" type="text" /> | |
<br /><br /> | |
Add a branch: | |
<br /> | |
<label for="tree_branches_attributes_0_name">Branch Name:</label> | |
<input id="tree_branches_attributes_0_name" name="tree[branches_attributes][0][name]" size="30" type="text" /> | |
<br /> | |
<input id="tree_submit" name="commit" type="submit" value="Save changes" /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tree < ActiveRecord::Base | |
has_many :branches | |
validates_presence_of :name | |
accepts_nested_attributes_for :branches, :allow_destroy => true, :reject_if => :all_blank | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment