Permalink
Browse files

scaffold user, club

  • Loading branch information...
1 parent 5d63bbb commit 573a67ce96b0a25b74fb573d145721f9788f82c2 @fr-fujiwara fr-fujiwara committed Apr 16, 2012
Showing with 1,027 additions and 0 deletions.
  1. +3 −0 app/assets/javascripts/clubs.js.coffee
  2. +3 −0 app/assets/javascripts/users.js.coffee
  3. +3 −0 app/assets/stylesheets/clubs.css.scss
  4. +56 −0 app/assets/stylesheets/scaffolds.css.scss
  5. +3 −0 app/assets/stylesheets/users.css.scss
  6. +83 −0 app/controllers/clubs_controller.rb
  7. +83 −0 app/controllers/users_controller.rb
  8. +2 −0 app/helpers/clubs_helper.rb
  9. +2 −0 app/helpers/users_helper.rb
  10. +2 −0 app/models/club.rb
  11. +2 −0 app/models/user.rb
  12. +13 −0 app/views/clubs/_form.html.haml
  13. +7 −0 app/views/clubs/edit.html.haml
  14. +19 −0 app/views/clubs/index.html.haml
  15. +5 −0 app/views/clubs/new.html.haml
  16. +9 −0 app/views/clubs/show.html.haml
  17. +16 −0 app/views/users/_form.html.haml
  18. +7 −0 app/views/users/edit.html.haml
  19. +21 −0 app/views/users/index.html.haml
  20. +5 −0 app/views/users/new.html.haml
  21. +12 −0 app/views/users/show.html.haml
  22. +4 −0 config/routes.rb
  23. +10 −0 db/migrate/20120416061301_create_users.rb
  24. +9 −0 db/migrate/20120416061347_create_clubs.rb
  25. +37 −0 db/schema.rb
  26. +164 −0 spec/controllers/clubs_controller_spec.rb
  27. +164 −0 spec/controllers/users_controller_spec.rb
  28. +15 −0 spec/helpers/clubs_helper_spec.rb
  29. +15 −0 spec/helpers/users_helper_spec.rb
  30. +5 −0 spec/models/club_spec.rb
  31. +5 −0 spec/models/user_spec.rb
  32. +11 −0 spec/requests/clubs_spec.rb
  33. +11 −0 spec/requests/users_spec.rb
  34. +35 −0 spec/routing/clubs_routing_spec.rb
  35. +35 −0 spec/routing/users_routing_spec.rb
  36. +18 −0 spec/views/clubs/edit.html.haml_spec.rb
  37. +20 −0 spec/views/clubs/index.html.haml_spec.rb
  38. +18 −0 spec/views/clubs/new.html.haml_spec.rb
  39. +15 −0 spec/views/clubs/show.html.haml_spec.rb
  40. +20 −0 spec/views/users/edit.html.haml_spec.rb
  41. +23 −0 spec/views/users/index.html.haml_spec.rb
  42. +20 −0 spec/views/users/new.html.haml_spec.rb
  43. +17 −0 spec/views/users/show.html.haml_spec.rb
@@ -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/
@@ -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/
@@ -0,0 +1,3 @@
+// Place all the styles related to the clubs controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -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; } }
@@ -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/
@@ -0,0 +1,83 @@
+class ClubsController < ApplicationController
+ # GET /clubs
+ # GET /clubs.json
+ def index
+ @clubs = Club.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @clubs }
+ end
+ end
+
+ # GET /clubs/1
+ # GET /clubs/1.json
+ def show
+ @club = Club.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @club }
+ end
+ end
+
+ # GET /clubs/new
+ # GET /clubs/new.json
+ def new
+ @club = Club.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @club }
+ end
+ end
+
+ # GET /clubs/1/edit
+ def edit
+ @club = Club.find(params[:id])
+ end
+
+ # POST /clubs
+ # POST /clubs.json
+ def create
+ @club = Club.new(params[:club])
+
+ respond_to do |format|
+ if @club.save
+ format.html { redirect_to @club, notice: 'Club was successfully created.' }
+ format.json { render json: @club, status: :created, location: @club }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @club.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /clubs/1
+ # PUT /clubs/1.json
+ def update
+ @club = Club.find(params[:id])
+
+ respond_to do |format|
+ if @club.update_attributes(params[:club])
+ format.html { redirect_to @club, notice: 'Club was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @club.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /clubs/1
+ # DELETE /clubs/1.json
+ def destroy
+ @club = Club.find(params[:id])
+ @club.destroy
+
+ respond_to do |format|
+ format.html { redirect_to clubs_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -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
@@ -0,0 +1,2 @@
+module ClubsHelper
+end
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
@@ -0,0 +1,2 @@
+class Club < ActiveRecord::Base
+end
View
@@ -0,0 +1,2 @@
+class User < ActiveRecord::Base
+end
@@ -0,0 +1,13 @@
+= form_for @club do |f|
+ -if @club.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@club.errors.count, "error")} prohibited this club from being saved:"
+ %ul
+ - @club.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .actions
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
+%h1 Editing club
+
+= render 'form'
+
+= link_to 'Show', @club
+\|
+= link_to 'Back', clubs_path
@@ -0,0 +1,19 @@
+%h1 Listing clubs
+
+%table
+ %tr
+ %th Name
+ %th
+ %th
+ %th
+
+ - @clubs.each do |club|
+ %tr
+ %td= club.name
+ %td= link_to 'Show', club
+ %td= link_to 'Edit', edit_club_path(club)
+ %td= link_to 'Destroy', club, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New Club', new_club_path
@@ -0,0 +1,5 @@
+%h1 New club
+
+= render 'form'
+
+= link_to 'Back', clubs_path
@@ -0,0 +1,9 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @club.name
+
+= link_to 'Edit', edit_club_path(@club)
+\|
+= link_to 'Back', clubs_path
@@ -0,0 +1,16 @@
+= form_for @user do |f|
+ -if @user.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:"
+ %ul
+ - @user.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .field
+ = f.label :club_id
+ = f.number_field :club_id
+ .actions
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
+%h1 Editing user
+
+= render 'form'
+
+= link_to 'Show', @user
+\|
+= link_to 'Back', users_path
@@ -0,0 +1,21 @@
+%h1 Listing users
+
+%table
+ %tr
+ %th Name
+ %th Club
+ %th
+ %th
+ %th
+
+ - @users.each do |user|
+ %tr
+ %td= user.name
+ %td= user.club_id
+ %td= link_to 'Show', user
+ %td= link_to 'Edit', edit_user_path(user)
+ %td= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New User', new_user_path
@@ -0,0 +1,5 @@
+%h1 New user
+
+= render 'form'
+
+= link_to 'Back', users_path
@@ -0,0 +1,12 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @user.name
+%p
+ %b Club:
+ = @user.club_id
+
+= link_to 'Edit', edit_user_path(@user)
+\|
+= link_to 'Back', users_path
View
@@ -1,4 +1,8 @@
C2::Application.routes.draw do
+ resources :clubs
+
+ resources :users
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.integer :club_id
+
+ t.timestamps
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 573a67c

Please sign in to comment.