Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

user scaffold

  • Loading branch information...
commit e4cfeda7bc88bd45f6fa9b12bb6d2b1a350aa70c 1 parent c082848
@shawndrost shawndrost authored
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -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; } }
View
83 app/controllers/users_controller.rb
@@ -0,0 +1,83 @@
+class UsersController < ApplicationController
+ # GET /users
+ # GET /users.json
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.json
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.json
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ # POST /users
+ # POST /users.json
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to @user, notice: 'User was successfully created.' }
+ format.json { render json: @user, status: :created, location: @user }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.json
+ def update
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to @user, notice: 'User was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.json
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to users_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
3  app/models/user.rb
@@ -0,0 +1,3 @@
+class User < ActiveRecord::Base
+ attr_accessible :birthday, :email, :facebook_uid, :level, :max_price, :name, :phone, :source, :twitter_uid, :why_english
+end
View
57 app/views/users/_form.html.erb
@@ -0,0 +1,57 @@
+<%= form_for(@user) do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :phone %><br />
+ <%= f.text_field :phone %>
+ </div>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :facebook_uid %><br />
+ <%= f.text_field :facebook_uid %>
+ </div>
+ <div class="field">
+ <%= f.label :twitter_uid %><br />
+ <%= f.text_field :twitter_uid %>
+ </div>
+ <div class="field">
+ <%= f.label :birthday %><br />
+ <%= f.date_select :birthday %>
+ </div>
+ <div class="field">
+ <%= f.label :why_english %><br />
+ <%= f.text_area :why_english %>
+ </div>
+ <div class="field">
+ <%= f.label :source %><br />
+ <%= f.text_area :source %>
+ </div>
+ <div class="field">
+ <%= f.label :level %><br />
+ <%= f.text_field :level %>
+ </div>
+ <div class="field">
+ <%= f.label :max_price %><br />
+ <%= f.text_field :max_price %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/users/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user %> |
+<%= link_to 'Back', users_path %>
View
41 app/views/users/index.html.erb
@@ -0,0 +1,41 @@
+<h1>Listing users</h1>
+
+<table>
+ <tr>
+ <th>Email</th>
+ <th>Phone</th>
+ <th>Name</th>
+ <th>Facebook uid</th>
+ <th>Twitter uid</th>
+ <th>Birthday</th>
+ <th>Why english</th>
+ <th>Source</th>
+ <th>Level</th>
+ <th>Max price</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.email %></td>
+ <td><%= user.phone %></td>
+ <td><%= user.name %></td>
+ <td><%= user.facebook_uid %></td>
+ <td><%= user.twitter_uid %></td>
+ <td><%= user.birthday %></td>
+ <td><%= user.why_english %></td>
+ <td><%= user.source %></td>
+ <td><%= user.level %></td>
+ <td><%= user.max_price %></td>
+ <td><%= link_to 'Show', user %></td>
+ <td><%= link_to 'Edit', edit_user_path(user) %></td>
+ <td><%= link_to 'Destroy', user, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New User', new_user_path %>
View
5 app/views/users/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
View
55 app/views/users/show.html.erb
@@ -0,0 +1,55 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Email:</b>
+ <%= @user.email %>
+</p>
+
+<p>
+ <b>Phone:</b>
+ <%= @user.phone %>
+</p>
+
+<p>
+ <b>Name:</b>
+ <%= @user.name %>
+</p>
+
+<p>
+ <b>Facebook uid:</b>
+ <%= @user.facebook_uid %>
+</p>
+
+<p>
+ <b>Twitter uid:</b>
+ <%= @user.twitter_uid %>
+</p>
+
+<p>
+ <b>Birthday:</b>
+ <%= @user.birthday %>
+</p>
+
+<p>
+ <b>Why english:</b>
+ <%= @user.why_english %>
+</p>
+
+<p>
+ <b>Source:</b>
+ <%= @user.source %>
+</p>
+
+<p>
+ <b>Level:</b>
+ <%= @user.level %>
+</p>
+
+<p>
+ <b>Max price:</b>
+ <%= @user.max_price %>
+</p>
+
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>
View
2  config/routes.rb
@@ -1,4 +1,6 @@
Koalabear::Application.routes.draw do
+ resources :users
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
18 db/migrate/20120407234132_create_users.rb
@@ -0,0 +1,18 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :email
+ t.string :phone
+ t.string :name
+ t.string :facebook_uid
+ t.string :twitter_uid
+ t.date :birthday
+ t.text :why_english
+ t.text :source
+ t.string :level
+ t.string :max_price
+
+ t.timestamps
+ end
+ end
+end
View
25 test/fixtures/users.yml
@@ -0,0 +1,25 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ email: MyString
+ phone: MyString
+ name: MyString
+ facebook_uid: MyString
+ twitter_uid: MyString
+ birthday: 2012-04-07
+ why_english: MyText
+ source: MyText
+ level: MyString
+ max_price: MyString
+
+two:
+ email: MyString
+ phone: MyString
+ name: MyString
+ facebook_uid: MyString
+ twitter_uid: MyString
+ birthday: 2012-04-07
+ why_english: MyText
+ source: MyText
+ level: MyString
+ max_price: MyString
View
49 test/functional/users_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionController::TestCase
+ setup do
+ @user = users(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:users)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create user" do
+ assert_difference('User.count') do
+ post :create, user: { birthday: @user.birthday, email: @user.email, facebook_uid: @user.facebook_uid, level: @user.level, max_price: @user.max_price, name: @user.name, phone: @user.phone, source: @user.source, twitter_uid: @user.twitter_uid, why_english: @user.why_english }
+ end
+
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should show user" do
+ get :show, id: @user
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @user
+ assert_response :success
+ end
+
+ test "should update user" do
+ put :update, id: @user, user: { birthday: @user.birthday, email: @user.email, facebook_uid: @user.facebook_uid, level: @user.level, max_price: @user.max_price, name: @user.name, phone: @user.phone, source: @user.source, twitter_uid: @user.twitter_uid, why_english: @user.why_english }
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should destroy user" do
+ assert_difference('User.count', -1) do
+ delete :destroy, id: @user
+ end
+
+ assert_redirected_to users_path
+ end
+end
View
4 test/unit/helpers/users_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class UsersHelperTest < ActionView::TestCase
+end
View
7 test/unit/user_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class UserTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.