Skip to content

Commit

Permalink
modified: Gemfile
Browse files Browse the repository at this point in the history
modified:   Gemfile.lock
--
Added the userstamp gem and the rails3_acts_as_paranoid gem

new file:   app/assets/javascripts/users.js.coffee
new file:   app/assets/stylesheets/users.css.scss
new file:   app/controllers/users_controller.rb
new file:   app/helpers/users_helper.rb
new file:   app/models/user.rb
new file:   app/views/users/_form.html.erb
new file:   app/views/users/edit.html.erb
new file:   app/views/users/index.html.erb
new file:   app/views/users/new.html.erb
new file:   app/views/users/show.html.erb
modified:   config/routes.rb
new file:   db/migrate/20121025001857_create_users.rb
new file:   test/fixtures/users.yml
new file:   test/functional/users_controller_test.rb
new file:   test/unit/helpers/users_helper_test.rb
new file:   test/unit/user_test.rb
--
Generated scaffolding for user table (closes #19)

modified:   app/controllers/application_controller.rb
modified:   app/models/project.rb
modified:   app/models/site.rb
new file:   app/models/user.rb
new file:   db/migrate/20121025001857_create_users.rb
new file:   db/migrate/20121025045908_add_user_stamp_to_projects.rb
new file:   db/migrate/20121025050112_add_user_stamp_to_sites.rb
--
Added support for created_by and updated_by in Users, Projects, and Sites (closes #11)

modified:   db/seeds.rb
--
Added seed db user and sections for seed data in dev and prod
  • Loading branch information
atruskie committed Oct 25, 2012
1 parent b2fe6ed commit 97cf6cd
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.js.coffee
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions app/assets/stylesheets/users.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
11 changes: 11 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
class ApplicationController < ActionController::Base
protect_from_forgery

# userstamp
include Userstamp

private

def set_stamper
# I expect this to fail
# hack while we have no authentication
User.stamper = User.first() #self.current_user
end
end
83 changes: 83 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
3 changes: 3 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ class Project < ActiveRecord::Base
has_many :sites, :through => :project_sites
accepts_nested_attributes_for :sites

# userstamp
stampable

validates :name, :presence => true
end
3 changes: 3 additions & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class Site < ActiveRecord::Base
has_many :projects_sites
has_many :projects, :through => :projects_sites

# userstamp
stampable

validates :name, :presence => true, :length => { :minimum => 2 }
validates :latitude, :presence => true, :numericality => true
validates :longitude, :presence => true, :numericality => true
Expand Down
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class User < ActiveRecord::Base
attr_accessible :display_name

# user stamp
model_stamper
stampable
end
21 changes: 21 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= 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 :display_name %><br />
<%= f.text_field :display_name %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing user</h1>

<%= render 'form' %>

<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>
23 changes: 23 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h1>Listing users</h1>

<table>
<tr>
<th>Display name</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @users.each do |user| %>
<tr>
<td><%= user.display_name %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New User', new_user_path %>
5 changes: 5 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New user</h1>

<%= render 'form' %>

<%= link_to 'Back', users_path %>
10 changes: 10 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p id="notice"><%= notice %></p>

<p>
<b>Display name:</b>
<%= @user.display_name %>
</p>


<%= link_to 'Edit', edit_user_path(@user) %> |
<%= link_to 'Back', users_path %>

0 comments on commit 97cf6cd

Please sign in to comment.