Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

scaffold user model and controller

  • Loading branch information...
commit ce8fa8094d7da4039891aedbf31919183969e7ee 1 parent 8b47eb8
@leemartin leemartin authored
View
22 app/controllers/users_controller.rb
@@ -0,0 +1,22 @@
+class UsersController < ApplicationController
+
+ def index
+
+ @users = User.all
+
+ end
+
+ def create
+
+ @user = User.new(params[:user])
+
+ if @user.save
+ flash[:notice] = 'User was successfully created.'
+ redirect_to(@user)
+ else
+ render :action => "new"
+ end
+
+ end
+
+end
View
2  app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
2  app/models/user.rb
@@ -0,0 +1,2 @@
+class User < ActiveRecord::Base
+end
View
17 app/views/layouts/users.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>Users: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
View
32 app/views/users/edit.html.erb
@@ -0,0 +1,32 @@
+<h1>Editing user</h1>
+
+<% form_for(@user) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :service %><br />
+ <%= f.text_field :service %>
+ </p>
+ <p>
+ <%= f.label :user_id %><br />
+ <%= f.text_field :user_id %>
+ </p>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </p>
+ <p>
+ <%= f.label :location %><br />
+ <%= f.text_field :location %>
+ </p>
+ <p>
+ <%= f.submit 'Update' %>
+ </p>
+<% end %>
+
+<%= link_to 'Show', @user %> |
+<%= link_to 'Back', users_path %>
View
28 app/views/users/index.html.erb
@@ -0,0 +1,28 @@
+<h1>Listing users</h1>
+
+<table>
+ <tr>
+ <th>Service</th>
+ <th>User</th>
+ <th>Name</th>
+ <th>Email</th>
+ <th>Location</th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%=h user.service %></td>
+ <td><%=h user.user_id %></td>
+ <td><%=h user.name %></td>
+ <td><%=h user.email %></td>
+ <td><%=h user.location %></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
31 app/views/users/new.html.erb
@@ -0,0 +1,31 @@
+<h1>New user</h1>
+
+<% form_for(@user) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :service %><br />
+ <%= f.text_field :service %>
+ </p>
+ <p>
+ <%= f.label :user_id %><br />
+ <%= f.text_field :user_id %>
+ </p>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </p>
+ <p>
+ <%= f.label :location %><br />
+ <%= f.text_field :location %>
+ </p>
+ <p>
+ <%= f.submit 'Create' %>
+ </p>
+<% end %>
+
+<%= link_to 'Back', users_path %>
View
28 app/views/users/show.html.erb
@@ -0,0 +1,28 @@
+<p>
+ <b>Service:</b>
+ <%=h @user.service %>
+</p>
+
+<p>
+ <b>User:</b>
+ <%=h @user.user_id %>
+</p>
+
+<p>
+ <b>Name:</b>
+ <%=h @user.name %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%=h @user.email %>
+</p>
+
+<p>
+ <b>Location:</b>
+ <%=h @user.location %>
+</p>
+
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>
View
2  config/routes.rb
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
+ map.resources :users
+
map.resource :session
map.resources :posts
View
17 db/migrate/20100831200227_create_users.rb
@@ -0,0 +1,17 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+ t.string :service
+ t.string :user_id
+ t.string :name
+ t.string :email
+ t.string :location
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
View
54 public/stylesheets/scaffold.css
@@ -0,0 +1,54 @@
+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; }
+
+.fieldWithErrors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#errorExplanation {
+ width: 400px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+
+#errorExplanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ background-color: #c00;
+ color: #fff;
+}
+
+#errorExplanation p {
+ color: #333;
+ margin-bottom: 0;
+ padding: 5px;
+}
+
+#errorExplanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
+
View
15 test/fixtures/users.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ service: MyString
+ user_id: MyString
+ name: MyString
+ email: MyString
+ location: MyString
+
+two:
+ service: MyString
+ user_id: MyString
+ name: MyString
+ email: MyString
+ location: MyString
View
45 test/functional/users_controller_test.rb
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionController::TestCase
+ 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 => { }
+ end
+
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should show user" do
+ get :show, :id => users(:one).to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => users(:one).to_param
+ assert_response :success
+ end
+
+ test "should update user" do
+ put :update, :id => users(:one).to_param, :user => { }
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should destroy user" do
+ assert_difference('User.count', -1) do
+ delete :destroy, :id => users(:one).to_param
+ 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
8 test/unit/user_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class UserTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.