Skip to content

Commit ce3f0a3

Browse files
committed
add users
1 parent 930e206 commit ce3f0a3

18 files changed

Lines changed: 330 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
body {
2+
background-color: #fff;
3+
color: #333;
4+
font-family: verdana, arial, helvetica, sans-serif;
5+
font-size: 13px;
6+
line-height: 18px; }
7+
8+
p, ol, ul, td {
9+
font-family: verdana, arial, helvetica, sans-serif;
10+
font-size: 13px;
11+
line-height: 18px; }
12+
13+
pre {
14+
background-color: #eee;
15+
padding: 10px;
16+
font-size: 11px; }
17+
18+
a {
19+
color: #000;
20+
&:visited {
21+
color: #666; }
22+
&:hover {
23+
color: #fff;
24+
background-color: #000; } }
25+
26+
div {
27+
&.field, &.actions {
28+
margin-bottom: 10px; } }
29+
30+
#notice {
31+
color: green; }
32+
33+
.field_with_errors {
34+
padding: 2px;
35+
background-color: red;
36+
display: table; }
37+
38+
#error_explanation {
39+
width: 450px;
40+
border: 2px solid red;
41+
padding: 7px;
42+
padding-bottom: 0;
43+
margin-bottom: 20px;
44+
background-color: #f0f0f0;
45+
h2 {
46+
text-align: left;
47+
font-weight: bold;
48+
padding: 5px 5px 5px 15px;
49+
font-size: 12px;
50+
margin: -7px;
51+
margin-bottom: 0px;
52+
background-color: #c00;
53+
color: #fff; }
54+
ul li {
55+
font-size: 12px;
56+
list-style: square; } }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the users controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
class UsersController < ApplicationController
2+
# GET /users
3+
# GET /users.json
4+
def index
5+
@users = User.all
6+
7+
respond_to do |format|
8+
format.html # index.html.erb
9+
format.json { render json: @users }
10+
end
11+
end
12+
13+
# GET /users/1
14+
# GET /users/1.json
15+
def show
16+
@user = User.find(params[:id])
17+
18+
respond_to do |format|
19+
format.html # show.html.erb
20+
format.json { render json: @user }
21+
end
22+
end
23+
24+
# GET /users/new
25+
# GET /users/new.json
26+
def new
27+
@user = User.new
28+
29+
respond_to do |format|
30+
format.html # new.html.erb
31+
format.json { render json: @user }
32+
end
33+
end
34+
35+
# GET /users/1/edit
36+
def edit
37+
@user = User.find(params[:id])
38+
end
39+
40+
# POST /users
41+
# POST /users.json
42+
def create
43+
@user = User.new(params[:user])
44+
45+
respond_to do |format|
46+
if @user.save
47+
format.html { redirect_to @user, notice: 'User was successfully created.' }
48+
format.json { render json: @user, status: :created, location: @user }
49+
else
50+
format.html { render action: "new" }
51+
format.json { render json: @user.errors, status: :unprocessable_entity }
52+
end
53+
end
54+
end
55+
56+
# PUT /users/1
57+
# PUT /users/1.json
58+
def update
59+
@user = User.find(params[:id])
60+
61+
respond_to do |format|
62+
if @user.update_attributes(params[:user])
63+
format.html { redirect_to @user, notice: 'User was successfully updated.' }
64+
format.json { head :no_content }
65+
else
66+
format.html { render action: "edit" }
67+
format.json { render json: @user.errors, status: :unprocessable_entity }
68+
end
69+
end
70+
end
71+
72+
# DELETE /users/1
73+
# DELETE /users/1.json
74+
def destroy
75+
@user = User.find(params[:id])
76+
@user.destroy
77+
78+
respond_to do |format|
79+
format.html { redirect_to users_url }
80+
format.json { head :no_content }
81+
end
82+
end
83+
end

app/helpers/users_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module UsersHelper
2+
end

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class User < ActiveRecord::Base
2+
attr_accessible :job_title, :name
3+
end

app/views/users/_form.html.erb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%= form_for(@user) do |f| %>
2+
<% if @user.errors.any? %>
3+
<div id="error_explanation">
4+
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
5+
6+
<ul>
7+
<% @user.errors.full_messages.each do |msg| %>
8+
<li><%= msg %></li>
9+
<% end %>
10+
</ul>
11+
</div>
12+
<% end %>
13+
14+
<div class="field">
15+
<%= f.label :name %><br />
16+
<%= f.text_field :name %>
17+
</div>
18+
<div class="field">
19+
<%= f.label :job_title %><br />
20+
<%= f.text_field :job_title %>
21+
</div>
22+
<div class="actions">
23+
<%= f.submit %>
24+
</div>
25+
<% end %>

app/views/users/edit.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1>Editing user</h1>
2+
3+
<%= render 'form' %>
4+
5+
<%= link_to 'Show', @user %> |
6+
<%= link_to 'Back', users_path %>

app/views/users/index.html.erb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<h1>Listing users</h1>
2+
3+
<table>
4+
<tr>
5+
<th>Name</th>
6+
<th>Job title</th>
7+
<th></th>
8+
<th></th>
9+
<th></th>
10+
</tr>
11+
12+
<% @users.each do |user| %>
13+
<tr>
14+
<td><%= user.name %></td>
15+
<td><%= user.job_title %></td>
16+
<td><%= link_to 'Show', user %></td>
17+
<td><%= link_to 'Edit', edit_user_path(user) %></td>
18+
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
19+
</tr>
20+
<% end %>
21+
</table>
22+
23+
<br />
24+
25+
<%= link_to 'New User', new_user_path %>

app/views/users/new.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h1>New user</h1>
2+
3+
<%= render 'form' %>
4+
5+
<%= link_to 'Back', users_path %>

0 commit comments

Comments
 (0)