-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffolding offices so we can play with some data
- Loading branch information
Pablo Villalba
committed
Nov 20, 2010
1 parent
0b13fd9
commit f1a26f4
Showing
12 changed files
with
247 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
class OfficesController < ApplicationController | ||
|
||
def index | ||
@offices = Office.all | ||
end | ||
|
||
def show | ||
@office = Office.find(params[:id]) | ||
end | ||
|
||
end | ||
def new | ||
@office = Office.new | ||
end | ||
|
||
def edit | ||
@office = Office.find(params[:id]) | ||
end | ||
|
||
def create | ||
@office = Office.new(params[:office]) | ||
|
||
if @office.save | ||
redirect_to(@office, :notice => 'Office was successfully created.') | ||
else | ||
render :action => "new" | ||
end | ||
end | ||
|
||
def update | ||
@office = Office.find(params[:id]) | ||
|
||
if @office.update_attributes(params[:office]) | ||
redirect_to(@office, :notice => 'Office was successfully updated.') | ||
else | ||
render :action => "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@office = Office.find(params[:id]) | ||
@office.destroy | ||
|
||
redirect_to(offices_url) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module OfficesHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Office < ActiveRecord::Base | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
= form_for(@office) do |f| | ||
- if @office.errors.any? | ||
#error_explanation | ||
%h2 | ||
== #{pluralize(@office.errors.count, "error")} prohibited this office from being saved: | ||
%ul | ||
- @office.errors.full_messages.each do |msg| | ||
%li= msg | ||
|
||
.field | ||
= f.label :name | ||
%br | ||
= f.text_field :name | ||
|
||
.field | ||
= f.label :description | ||
%br | ||
= f.text_area :description | ||
|
||
.field | ||
= f.label :data | ||
%br | ||
= f.text_field :data | ||
|
||
.field | ||
= f.label :location | ||
%br | ||
= f.text_field :location | ||
|
||
.field | ||
= f.label :desks | ||
%br | ||
= f.text_field :desks | ||
|
||
.actions | ||
= f.submit |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%h1 Editing office | ||
|
||
= render 'form' | ||
|
||
= link_to 'Show', @office | ||
= link_to 'Back', offices_path |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h1>Listing offices</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Description</th> | ||
<th>Data</th> | ||
<th>Location</th> | ||
<th>Desks</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @offices.each do |office| %> | ||
<tr> | ||
<td><%= office.name %></td> | ||
<td><%= office.description %></td> | ||
<td><%= office.data %></td> | ||
<td><%= office.location %></td> | ||
<td><%= office.desks %></td> | ||
<td><%= link_to 'Show', office %></td> | ||
<td><%= link_to 'Edit', edit_office_path(office) %></td> | ||
<td><%= link_to 'Destroy', office, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Office', new_office_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%h1 New office | ||
|
||
= render 'form' | ||
|
||
= link_to 'Back', offices_path |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<b>Name:</b> | ||
<%= @office.name %> | ||
</p> | ||
|
||
<p> | ||
<b>Description:</b> | ||
<%= @office.description %> | ||
</p> | ||
|
||
<p> | ||
<b>Data:</b> | ||
<%= @office.data %> | ||
</p> | ||
|
||
<p> | ||
<b>Location:</b> | ||
<%= @office.location %> | ||
</p> | ||
|
||
<p> | ||
<b>Desks:</b> | ||
<%= @office.desks %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_office_path(@office) %> | | ||
<%= link_to 'Back', offices_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateOffices < ActiveRecord::Migration | ||
def self.up | ||
create_table :offices do |t| | ||
t.string :name | ||
t.text :description | ||
t.text :data | ||
t.string :location | ||
t.integer :desks | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :offices | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended to check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(:version => 20101120115156) do | ||
|
||
create_table "offices", :force => true do |t| | ||
t.string "name" | ||
t.text "description" | ||
t.text "data" | ||
t.string "location" | ||
t.integer "desks" | ||
t.datetime "created_at" | ||
t.datetime "updated_at" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
body { background-color: #fff; color: #333; } | ||
|
||
body, p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { color: #000; } | ||
a:visited { color: #666; } | ||
a:hover { color: #fff; background-color:#000; } | ||
|
||
div.field, div.actions { | ||
margin-bottom: 10px; | ||
} | ||
|
||
#notice { | ||
color: green; | ||
} | ||
|
||
.field_with_errors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#error_explanation { | ||
width: 450px; | ||
border: 2px solid red; | ||
padding: 7px; | ||
padding-bottom: 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
#error_explanation h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px; | ||
margin-bottom: 0px; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
#error_explanation ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} |