Created
July 14, 2013 19:23
-
-
Save biographie/5995461 to your computer and use it in GitHub Desktop.
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>Add New Company</h1> | |
<%= form_for(@company) do |f| %> | |
<%= f.label :name %> | |
<%= f.text_field :name %> | |
<%= f.label :address %> | |
<%= f.text_field :address %> | |
<%= f.nested_fields_for :phone_numbers do |f| | |
render 'phone', f: f | |
end %> | |
<%= f.label :email %> | |
<%= f.text_field :email %> | |
<%= f.label :background %> | |
<%= f.text_area :background %> | |
<%= f.submit "Add Company", class: "btn btn-large btn-primary" %> | |
<% end %> | |
class CompaniesController < ApplicationController | |
def index | |
@companies = Company.all | |
end | |
def new | |
@company = Company.new | |
@company.phone_numbers.build | |
end | |
def show | |
@company = Company.find(params[:id]) | |
end | |
def create | |
@company = Company.create(params[:company]) | |
if @company.save | |
redirect_to "/companies" | |
else | |
render 'new' | |
end | |
end | |
def edit | |
end | |
end | |
# == Schema Information | |
# | |
# Table name: companies | |
# | |
# id :integer not null, primary key | |
# name :text | |
# email :text | |
# address :text | |
# background :text | |
# logo :text | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# user_id :integer | |
# | |
class Company < ActiveRecord::Base | |
attr_accessible :address, :background, :email, :logo, :name, :phone_numbers_attributes | |
has_many :contacts | |
has_many :deals | |
has_many :tasks | |
has_many :activities | |
belongs_to :users | |
has_many :phone_numbers | |
accepts_nested_attributes_for :phone_numbers | |
end | |
# == Schema Information | |
# | |
# Table name: phone_numbers | |
# | |
# id :integer not null, primary key | |
# place :string(255) | |
# company_id :integer | |
# contact_id :integer | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# | |
class PhoneNumber < ActiveRecord::Base | |
attr_accessible :company_id, :contact_id, :place | |
belongs_to :company_id | |
end | |
<fieldset class="item"> | |
<%= f.label :place %> | |
<%= f.select :place, ['Home', 'Work', 'Other'] %> | |
<%= f.label :number %> | |
<%= f.text_field :number, size: '20' %> | |
<a href="#" class="remove" data-confirm="Are you sure?">remove</a> | |
<%= f.hidden_field :id %> | |
<%= f.hidden_field :_destroy %> | |
</fieldset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment