Skip to content

Commit

Permalink
Scaffolding offices so we can play with some data
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Villalba committed Nov 20, 2010
1 parent 0b13fd9 commit f1a26f4
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 2 deletions.
38 changes: 37 additions & 1 deletion app/controllers/offices_controller.rb
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
2 changes: 2 additions & 0 deletions app/helpers/offices_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module OfficesHelper
end
2 changes: 2 additions & 0 deletions app/models/office.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Office < ActiveRecord::Base
end
36 changes: 36 additions & 0 deletions app/views/offices/_form.haml
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
6 changes: 6 additions & 0 deletions app/views/offices/edit.haml
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
1 change: 0 additions & 1 deletion app/views/offices/index.haml

This file was deleted.

31 changes: 31 additions & 0 deletions app/views/offices/index.html.erb
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 %>
5 changes: 5 additions & 0 deletions app/views/offices/new.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%h1 New office

= render 'form'

= link_to 'Back', offices_path
30 changes: 30 additions & 0 deletions app/views/offices/show.html.erb
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 %>
17 changes: 17 additions & 0 deletions db/migrate/20101120115156_create_offices.rb
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
25 changes: 25 additions & 0 deletions db/schema.rb
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
56 changes: 56 additions & 0 deletions public/stylesheets/scaffold.css
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;
}

0 comments on commit f1a26f4

Please sign in to comment.