Skip to content
Browse files

added model users and cars

  • Loading branch information...
1 parent 1b46259 commit 0e4f629b1efb4f52e72ec07409f22d1bfb00e30c @munya committed May 27, 2013
View
3 app/assets/javascripts/cars.js.coffee
@@ -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/
View
3 app/assets/javascripts/users.js.coffee
@@ -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/
View
3 app/assets/stylesheets/cars.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Cars controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3 app/assets/stylesheets/users.css.scss
@@ -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/
View
83 app/controllers/cars_controller.rb
@@ -0,0 +1,83 @@
+class CarsController < ApplicationController
+ # GET /cars
+ # GET /cars.json
+ def index
+ @cars = Car.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @cars }
+ end
+ end
+
+ # GET /cars/1
+ # GET /cars/1.json
+ def show
+ @car = Car.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @car }
+ end
+ end
+
+ # GET /cars/new
+ # GET /cars/new.json
+ def new
+ @car = Car.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @car }
+ end
+ end
+
+ # GET /cars/1/edit
+ def edit
+ @car = Car.find(params[:id])
+ end
+
+ # POST /cars
+ # POST /cars.json
+ def create
+ @car = Car.new(params[:car])
+
+ respond_to do |format|
+ if @car.save
+ format.html { redirect_to @car, notice: 'Car was successfully created.' }
+ format.json { render json: @car, status: :created, location: @car }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @car.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /cars/1
+ # PUT /cars/1.json
+ def update
+ @car = Car.find(params[:id])
+
+ respond_to do |format|
+ if @car.update_attributes(params[:car])
+ format.html { redirect_to @car, notice: 'Car was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @car.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /cars/1
+ # DELETE /cars/1.json
+ def destroy
+ @car = Car.find(params[:id])
+ @car.destroy
+
+ respond_to do |format|
+ format.html { redirect_to cars_url }
+ format.json { head :no_content }
+ end
+ end
+end
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
2 app/helpers/cars_helper.rb
@@ -0,0 +1,2 @@
+module CarsHelper
+end
View
2 app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
3 app/models/car.rb
@@ -0,0 +1,3 @@
+class Car < ActiveRecord::Base
+ attr_accessible :car_model, :color, :driver_id, :number
+end
View
3 app/models/user.rb
@@ -0,0 +1,3 @@
+class User < ActiveRecord::Base
+ attr_accessible :login, :name, :password, :type
+end
View
33 app/views/cars/_form.html.erb
@@ -0,0 +1,33 @@
+<%= form_for(@car) do |f| %>
+ <% if @car.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@car.errors.count, "error") %> prohibited this car from being saved:</h2>
+
+ <ul>
+ <% @car.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :car_model %><br />
+ <%= f.text_field :car_model %>
+ </div>
+ <div class="field">
+ <%= f.label :number %><br />
+ <%= f.text_field :number %>
+ </div>
+ <div class="field">
+ <%= f.label :color %><br />
+ <%= f.text_field :color %>
+ </div>
+ <div class="field">
+ <%= f.label :driver_id %><br />
+ <%= f.number_field :driver_id %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/cars/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing car</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @car %> |
+<%= link_to 'Back', cars_path %>
View
29 app/views/cars/index.html.erb
@@ -0,0 +1,29 @@
+<h1>Listing cars</h1>
+
+<table>
+ <tr>
+ <th>Car model</th>
+ <th>Number</th>
+ <th>Color</th>
+ <th>Driver</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @cars.each do |car| %>
+ <tr>
+ <td><%= car.car_model %></td>
+ <td><%= car.number %></td>
+ <td><%= car.color %></td>
+ <td><%= car.driver_id %></td>
+ <td><%= link_to 'Show', car %></td>
+ <td><%= link_to 'Edit', edit_car_path(car) %></td>
+ <td><%= link_to 'Destroy', car, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Car', new_car_path %>
View
5 app/views/cars/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New car</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', cars_path %>
View
25 app/views/cars/show.html.erb
@@ -0,0 +1,25 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Car model:</b>
+ <%= @car.car_model %>
+</p>
+
+<p>
+ <b>Number:</b>
+ <%= @car.number %>
+</p>
+
+<p>
+ <b>Color:</b>
+ <%= @car.color %>
+</p>
+
+<p>
+ <b>Driver:</b>
+ <%= @car.driver_id %>
+</p>
+
+
+<%= link_to 'Edit', edit_car_path(@car) %> |
+<%= link_to 'Back', cars_path %>
View
2 app/views/checkins/index.html.erb
@@ -1,6 +1,6 @@
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
-<div id="map" style="width: 600px; height: 500px;"></div>
+<div id="map" style="width: 100%; height: 500px;"></div>
<h1>Listing checkins</h1>
View
33 app/views/users/_form.html.erb
@@ -0,0 +1,33 @@
+<%= 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 :login %><br />
+ <%= f.number_field :login %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.text_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :type %><br />
+ <%= f.text_field :type %>
+ </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
29 app/views/users/index.html.erb
@@ -0,0 +1,29 @@
+<h1>Listing users</h1>
+
+<table>
+ <tr>
+ <th>Login</th>
+ <th>Password</th>
+ <th>Name</th>
+ <th>Type</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.login %></td>
+ <td><%= user.password %></td>
+ <td><%= user.name %></td>
+ <td><%= user.type %></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
25 app/views/users/show.html.erb
@@ -0,0 +1,25 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Login:</b>
+ <%= @user.login %>
+</p>
+
+<p>
+ <b>Password:</b>
+ <%= @user.password %>
+</p>
+
+<p>
+ <b>Name:</b>
+ <%= @user.name %>
+</p>
+
+<p>
+ <b>Type:</b>
+ <%= @user.type %>
+</p>
+
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>
View
4 config/routes.rb
@@ -1,4 +1,8 @@
PartyEvent::Application.routes.draw do
+ resources :users
+
+ resources :cars
+
resources :checkins
# The priority is based upon order of creation:
View
12 db/migrate/20130527201330_create_cars.rb
@@ -0,0 +1,12 @@
+class CreateCars < ActiveRecord::Migration
+ def change
+ create_table :cars do |t|
+ t.string :car_model
+ t.string :number
+ t.string :color
+ t.integer :driver_id
+
+ t.timestamps
+ end
+ end
+end
View
12 db/migrate/20130527201438_create_users.rb
@@ -0,0 +1,12 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.integer :login
+ t.string :password
+ t.string :name
+ t.string :type
+
+ t.timestamps
+ end
+ end
+end
View
2 db/schema.rb
@@ -18,4 +18,6 @@
t.spatial "location", :limit => {:srid=>4326, :type=>"point", :geographic=>true}
end
+ add_index "checkins", ["location"], :name => "index_checkins_on_location", :spatial => true
+
end
View
13 test/fixtures/cars.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ car_model: MyString
+ number: MyString
+ color: MyString
+ driver_id: 1
+
+two:
+ car_model: MyString
+ number: MyString
+ color: MyString
+ driver_id: 1
View
13 test/fixtures/users.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ login: 1
+ password: MyString
+ name: MyString
+ type:
+
+two:
+ login: 1
+ password: MyString
+ name: MyString
+ type:
View
49 test/functional/cars_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class CarsControllerTest < ActionController::TestCase
+ setup do
+ @car = cars(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:cars)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create car" do
+ assert_difference('Car.count') do
+ post :create, car: { car_model: @car.car_model, color: @car.color, driver_id: @car.driver_id, number: @car.number }
+ end
+
+ assert_redirected_to car_path(assigns(:car))
+ end
+
+ test "should show car" do
+ get :show, id: @car
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @car
+ assert_response :success
+ end
+
+ test "should update car" do
+ put :update, id: @car, car: { car_model: @car.car_model, color: @car.color, driver_id: @car.driver_id, number: @car.number }
+ assert_redirected_to car_path(assigns(:car))
+ end
+
+ test "should destroy car" do
+ assert_difference('Car.count', -1) do
+ delete :destroy, id: @car
+ end
+
+ assert_redirected_to cars_path
+ end
+end
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: { login: @user.login, name: @user.name, password: @user.password, type: @user.type }
+ 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: { login: @user.login, name: @user.name, password: @user.password, type: @user.type }
+ 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
7 test/unit/car_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CarTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/cars_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class CarsHelperTest < ActionView::TestCase
+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

0 comments on commit 0e4f629

Please sign in to comment.
Something went wrong with that request. Please try again.