Adding scaffolding for "Person"
This commit is contained in:
3
rails/gerbil/app/assets/javascripts/people.js.coffee
Normal file
3
rails/gerbil/app/assets/javascripts/people.js.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
3
rails/gerbil/app/assets/stylesheets/people.css.scss
Normal file
3
rails/gerbil/app/assets/stylesheets/people.css.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the People controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
56
rails/gerbil/app/assets/stylesheets/scaffolds.css.scss
Normal file
56
rails/gerbil/app/assets/stylesheets/scaffolds.css.scss
Normal file
@@ -0,0 +1,56 @@
|
||||
body {
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px; }
|
||||
|
||||
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;
|
||||
&:visited {
|
||||
color: #666; }
|
||||
&:hover {
|
||||
color: #fff;
|
||||
background-color: #000; } }
|
||||
|
||||
div {
|
||||
&.field, &.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;
|
||||
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; }
|
||||
ul li {
|
||||
font-size: 12px;
|
||||
list-style: square; } }
|
83
rails/gerbil/app/controllers/people_controller.rb
Normal file
83
rails/gerbil/app/controllers/people_controller.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
class PeopleController < ApplicationController
|
||||
# GET /people
|
||||
# GET /people.json
|
||||
def index
|
||||
@people = Person.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render :json => @people }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /people/1
|
||||
# GET /people/1.json
|
||||
def show
|
||||
@person = Person.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render :json => @person }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /people/new
|
||||
# GET /people/new.json
|
||||
def new
|
||||
@person = Person.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render :json => @person }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /people/1/edit
|
||||
def edit
|
||||
@person = Person.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /people
|
||||
# POST /people.json
|
||||
def create
|
||||
@person = Person.new(params[:person])
|
||||
|
||||
respond_to do |format|
|
||||
if @person.save
|
||||
format.html { redirect_to @person, :notice => 'Person was successfully created.' }
|
||||
format.json { render :json => @person, :status => :created, :location => @person }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.json { render :json => @person.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /people/1
|
||||
# PUT /people/1.json
|
||||
def update
|
||||
@person = Person.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @person.update_attributes(params[:person])
|
||||
format.html { redirect_to @person, :notice => 'Person was successfully updated.' }
|
||||
format.json { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.json { render :json => @person.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /people/1
|
||||
# DELETE /people/1.json
|
||||
def destroy
|
||||
@person = Person.find(params[:id])
|
||||
@person.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to people_url }
|
||||
format.json { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
2
rails/gerbil/app/helpers/people_helper.rb
Normal file
2
rails/gerbil/app/helpers/people_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module PeopleHelper
|
||||
end
|
2
rails/gerbil/app/models/person.rb
Normal file
2
rails/gerbil/app/models/person.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Person < ActiveRecord::Base
|
||||
end
|
29
rails/gerbil/app/views/people/_form.html.erb
Normal file
29
rails/gerbil/app/views/people/_form.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<%= form_for(@person) do |f| %>
|
||||
<% if @person.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@person.errors.count, "error") %> prohibited this person from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @person.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :name %><br />
|
||||
<%= f.text_field :name %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :age %><br />
|
||||
<%= f.number_field :age %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :zipcode %><br />
|
||||
<%= f.text_field :zipcode %>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
6
rails/gerbil/app/views/people/edit.html.erb
Normal file
6
rails/gerbil/app/views/people/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing person</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @person %> |
|
||||
<%= link_to 'Back', people_path %>
|
27
rails/gerbil/app/views/people/index.html.erb
Normal file
27
rails/gerbil/app/views/people/index.html.erb
Normal file
@@ -0,0 +1,27 @@
|
||||
<h1>Listing people</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Age</th>
|
||||
<th>Zipcode</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @people.each do |person| %>
|
||||
<tr>
|
||||
<td><%= person.name %></td>
|
||||
<td><%= person.age %></td>
|
||||
<td><%= person.zipcode %></td>
|
||||
<td><%= link_to 'Show', person %></td>
|
||||
<td><%= link_to 'Edit', edit_person_path(person) %></td>
|
||||
<td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New Person', new_person_path %>
|
5
rails/gerbil/app/views/people/new.html.erb
Normal file
5
rails/gerbil/app/views/people/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New person</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', people_path %>
|
20
rails/gerbil/app/views/people/show.html.erb
Normal file
20
rails/gerbil/app/views/people/show.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Name:</b>
|
||||
<%= @person.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Age:</b>
|
||||
<%= @person.age %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Zipcode:</b>
|
||||
<%= @person.zipcode %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_person_path(@person) %> |
|
||||
<%= link_to 'Back', people_path %>
|
Reference in New Issue
Block a user