Created
March 26, 2012 06:21
-
-
Save lscott3/2203389 to your computer and use it in GitHub Desktop.
Builder
This file contains 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 Account < ActiveRecord::Base | |
belongs_to :package | |
has_many :users | |
has_many :clients | |
has_many :items | |
has_many :attributes | |
has_many :notes | |
accepts_nested_attributes_for :users | |
accepts_nested_attributes_for :clients | |
accepts_nested_attributes_for :attributes | |
accepts_nested_attributes_for :notes | |
accepts_nested_attributes_for :items | |
authenticates_many :user_sessions, :scope_cookies => true, :find_options => { :limit => 1 } | |
end |
This file contains 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 Item < ActiveRecord::Base | |
has_many :attributes | |
has_many :notes, :as => :noteable | |
belongs_to :account | |
belongs_to :client | |
accepts_nested_attributes_for :attributes | |
accepts_nested_attributes_for :notes | |
before_save :create_service_tag | |
def create_service_tag | |
if service_tag.blank? | |
self.service_tag = SecureRandom.hex(3) | |
end | |
end | |
end |
This file contains 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 ItemsController < ApplicationController | |
before_filter :require_user, :except => [:search] | |
def new | |
@item = current_user.account.items.build | |
@item.notes.build #this line here | |
3.times { @item.attributes.build } | |
end | |
end |
This file contains 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
<h1>New Item</h1> | |
<%= form_for @item do |f| %> | |
<%= f.label :name %> | |
<%= f.text_field :name %> | |
<%= f.fields_for :attributes do |a| %> | |
<%= a.label :name %> | |
<%= a.text_field :name %> | |
<%= a.label :value %> | |
<%= a.text_field :value %> | |
<% end -%> | |
<%= f.fields_for :notes do |note| %> | |
<%= note.label :note %> | |
<%= note.text_field :note %> | |
<% end -%> | |
<%= f.submit "Create Item" %> | |
<% end -%> |
This file contains 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 Note < ActiveRecord::Base | |
belongs_to :account | |
belongs_to :noteable, :polymorphic => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment