Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Created basic Company model

  • Loading branch information...
commit 4b554ece66d3d0066a9b66daae52cf7c086820f3 1 parent 8def1f2
Jeff Casimir jcasimir authored
41 app/controllers/companies_controller.rb
... ... @@ -0,0 +1,41 @@
  1 +class CompaniesController < ApplicationController
  2 + def index
  3 + @companies = Company.all
  4 + end
  5 +
  6 + def show
  7 + @company = Company.find(params[:id])
  8 + end
  9 +
  10 + def new
  11 + @company = Company.new
  12 + end
  13 +
  14 + def create
  15 + @company = Company.new(params[:company])
  16 + if @company.save
  17 + redirect_to @company, :notice => "Successfully created company."
  18 + else
  19 + render :action => 'new'
  20 + end
  21 + end
  22 +
  23 + def edit
  24 + @company = Company.find(params[:id])
  25 + end
  26 +
  27 + def update
  28 + @company = Company.find(params[:id])
  29 + if @company.update_attributes(params[:company])
  30 + redirect_to @company, :notice => "Successfully updated company."
  31 + else
  32 + render :action => 'edit'
  33 + end
  34 + end
  35 +
  36 + def destroy
  37 + @company = Company.find(params[:id])
  38 + @company.destroy
  39 + redirect_to companies_url, :notice => "Successfully destroyed company."
  40 + end
  41 +end
2  app/helpers/companies_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module CompaniesHelper
  2 +end
3  app/models/company.rb
... ... @@ -0,0 +1,3 @@
  1 +class Company < ActiveRecord::Base
  2 + attr_accessible :name
  3 +end
8 app/views/companies/_form.html.erb
... ... @@ -0,0 +1,8 @@
  1 +<%= form_for @company do |f| %>
  2 + <%= f.error_messages %>
  3 + <p>
  4 + <%= f.label :name %><br />
  5 + <%= f.text_field :name %>
  6 + </p>
  7 + <p><%= f.submit %></p>
  8 +<% end %>
8 app/views/companies/edit.html.erb
... ... @@ -0,0 +1,8 @@
  1 +<% title "Edit Company" %>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<p>
  6 + <%= link_to "Show", @company %> |
  7 + <%= link_to "View All", companies_path %>
  8 +</p>
17 app/views/companies/index.html.erb
... ... @@ -0,0 +1,17 @@
  1 +<% title "Companies" %>
  2 +
  3 +<table>
  4 + <tr>
  5 + <th>Name</th>
  6 + </tr>
  7 + <% for company in @companies %>
  8 + <tr>
  9 + <td><%= company.name %></td>
  10 + <td><%= link_to "Show", company %></td>
  11 + <td><%= link_to "Edit", edit_company_path(company) %></td>
  12 + <td><%= link_to "Destroy", company, :confirm => 'Are you sure?', :method => :delete %></td>
  13 + </tr>
  14 + <% end %>
  15 +</table>
  16 +
  17 +<p><%= link_to "New Company", new_company_path %></p>
5 app/views/companies/new.html.erb
... ... @@ -0,0 +1,5 @@
  1 +<% title "New Company" %>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<p><%= link_to "Back to List", companies_path %></p>
12 app/views/companies/show.html.erb
... ... @@ -0,0 +1,12 @@
  1 +<% title "Company" %>
  2 +
  3 +<p>
  4 + <strong>Name:</strong>
  5 + <%= @company.name %>
  6 +</p>
  7 +
  8 +<p>
  9 + <%= link_to "Edit", edit_company_path(@company) %> |
  10 + <%= link_to "Destroy", @company, :confirm => 'Are you sure?', :method => :delete %> |
  11 + <%= link_to "View All", companies_path %>
  12 +</p>
2  config/routes.rb
... ... @@ -1,4 +1,6 @@
1 1 JSContact::Application.routes.draw do
  2 + resources :companies
  3 +
2 4 resources :email_addresses
3 5
4 6 resources :phone_numbers
12 db/migrate/20110420135545_create_companies.rb
... ... @@ -0,0 +1,12 @@
  1 +class CreateCompanies < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :companies do |t|
  4 + t.string :name
  5 + t.timestamps
  6 + end
  7 + end
  8 +
  9 + def self.down
  10 + drop_table :companies
  11 + end
  12 +end
8 db/schema.rb
@@ -10,7 +10,13 @@
10 10 #
11 11 # It's strongly recommended to check this file into your version control system.
12 12
13   -ActiveRecord::Schema.define(:version => 20110419213031) do
  13 +ActiveRecord::Schema.define(:version => 20110420135545) do
  14 +
  15 + create_table "companies", :force => true do |t|
  16 + t.string "name"
  17 + t.datetime "created_at"
  18 + t.datetime "updated_at"
  19 + end
14 20
15 21 create_table "email_addresses", :force => true do |t|
16 22 t.string "address"
57 spec/controllers/companies_controller_spec.rb
... ... @@ -0,0 +1,57 @@
  1 +# require File.dirname(__FILE__) + '/../spec_helper'
  2 +#
  3 +# describe CompaniesController do
  4 +# fixtures :all
  5 +# render_views
  6 +#
  7 +# it "index action should render index template" do
  8 +# get :index
  9 +# response.should render_template(:index)
  10 +# end
  11 +#
  12 +# it "show action should render show template" do
  13 +# get :show, :id => Company.first
  14 +# response.should render_template(:show)
  15 +# end
  16 +#
  17 +# it "new action should render new template" do
  18 +# get :new
  19 +# response.should render_template(:new)
  20 +# end
  21 +#
  22 +# it "create action should render new template when model is invalid" do
  23 +# Company.any_instance.stubs(:valid?).returns(false)
  24 +# post :create
  25 +# response.should render_template(:new)
  26 +# end
  27 +#
  28 +# it "create action should redirect when model is valid" do
  29 +# Company.any_instance.stubs(:valid?).returns(true)
  30 +# post :create
  31 +# response.should redirect_to(company_url(assigns[:company]))
  32 +# end
  33 +#
  34 +# it "edit action should render edit template" do
  35 +# get :edit, :id => Company.first
  36 +# response.should render_template(:edit)
  37 +# end
  38 +#
  39 +# it "update action should render edit template when model is invalid" do
  40 +# Company.any_instance.stubs(:valid?).returns(false)
  41 +# put :update, :id => Company.first
  42 +# response.should render_template(:edit)
  43 +# end
  44 +#
  45 +# it "update action should redirect when model is valid" do
  46 +# Company.any_instance.stubs(:valid?).returns(true)
  47 +# put :update, :id => Company.first
  48 +# response.should redirect_to(company_url(assigns[:company]))
  49 +# end
  50 +#
  51 +# it "destroy action should destroy model and redirect to index action" do
  52 +# company = Company.first
  53 +# delete :destroy, :id => company
  54 +# response.should redirect_to(companies_url)
  55 +# Company.exists?(company.id).should be_false
  56 +# end
  57 +# end
5 spec/fixtures/companies.yml
... ... @@ -0,0 +1,5 @@
  1 +one:
  2 + name: MyString
  3 +
  4 +two:
  5 + name: MyString
7 spec/models/company_spec.rb
... ... @@ -0,0 +1,7 @@
  1 +require File.dirname(__FILE__) + '/../spec_helper'
  2 +
  3 +describe Company do
  4 + it "should be valid" do
  5 + Company.new.should be_valid
  6 + end
  7 +end

0 comments on commit 4b554ec

Please sign in to comment.
Something went wrong with that request. Please try again.