Permalink
Browse files

implement

  • Loading branch information...
1 parent 0b0974e commit 108c98fa3e12f0758359aa8fa03602d4df44f615 @maccman committed May 21, 2011
View
@@ -6,6 +6,7 @@ gem 'rails', '3.0.7'
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
+gem 'thin'
# Use unicorn as the web server
# gem 'unicorn'
View
@@ -0,0 +1,80 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.7)
+ actionpack (= 3.0.7)
+ mail (~> 2.2.15)
+ actionpack (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.5.0)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.7)
+ activesupport (= 3.0.7)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ activesupport (3.0.7)
+ arel (2.0.10)
+ builder (2.1.2)
+ daemons (1.1.3)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ eventmachine (0.12.10)
+ i18n (0.5.0)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.2.2)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.7)
+ actionmailer (= 3.0.7)
+ actionpack (= 3.0.7)
+ activerecord (= 3.0.7)
+ activeresource (= 3.0.7)
+ activesupport (= 3.0.7)
+ bundler (~> 1.0)
+ railties (= 3.0.7)
+ railties (3.0.7)
+ actionpack (= 3.0.7)
+ activesupport (= 3.0.7)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.9.0)
+ sqlite3 (1.3.3)
+ thin (1.2.11)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.27)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rails (= 3.0.7)
+ sqlite3
+ thin
View
@@ -4,4 +4,14 @@
require File.expand_path('../config/application', __FILE__)
require 'rake'
+module ::Airguide
+ class Application
+ include Rake::DSL
+ end
+end
+
+module ::RakeFileUtils
+ extend Rake::FileUtilsExt
+end
+
Airguide::Application.load_tasks
@@ -0,0 +1,83 @@
+class DevicesController < ApplicationController
+ # GET /devices
+ # GET /devices.xml
+ def index
+ @devices = Device.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @devices }
+ end
+ end
+
+ # GET /devices/1
+ # GET /devices/1.xml
+ def show
+ @device = Device.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @device }
+ end
+ end
+
+ # GET /devices/new
+ # GET /devices/new.xml
+ def new
+ @device = Device.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @device }
+ end
+ end
+
+ # GET /devices/1/edit
+ def edit
+ @device = Device.find(params[:id])
+ end
+
+ # POST /devices
+ # POST /devices.xml
+ def create
+ @device = Device.new(params[:device])
+
+ respond_to do |format|
+ if @device.save
+ format.html { redirect_to(@device, :notice => 'Device was successfully created.') }
+ format.xml { render :xml => @device, :status => :created, :location => @device }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @device.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /devices/1
+ # PUT /devices/1.xml
+ def update
+ @device = Device.find(params[:id])
+
+ respond_to do |format|
+ if @device.update_attributes(params[:device])
+ format.html { redirect_to(@device, :notice => 'Device was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @device.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /devices/1
+ # DELETE /devices/1.xml
+ def destroy
+ @device = Device.find(params[:id])
+ @device.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(devices_url) }
+ format.xml { head :ok }
+ end
+ end
+end
@@ -0,0 +1,97 @@
+class UsersController < ApplicationController
+ before_filter :find_user, :except => [:index, :new, :create]
+ before_filter :find_devices, :except => [:index, :create]
+
+ # GET /users
+ # GET /users.xml
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.xml
+ def show
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.xml
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ end
+
+ # POST /users
+ # POST /users.xml
+ def create
+ @user = User.new(params[:user])
+
+ if params[:device_id]
+ @user.device = Device.find(params[:device_id])
+ end
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to(@user, :notice => 'User was successfully created.') }
+ format.xml { render :xml => @user, :status => :created, :location => @user }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.xml
+ def update
+ if params[:device_id].present?
+ @user.device = Device.find(params[:device_id])
+ end
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.xml
+ def destroy
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(users_url) }
+ format.xml { head :ok }
+ end
+ end
+
+ protected
+ def find_user
+ @user = User.find(params[:id])
+ end
+
+ def find_devices
+ @devices = Device.all
+ end
+end
@@ -0,0 +1,2 @@
+module DevicesHelper
+end
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
@@ -0,0 +1,13 @@
+class Device < ActiveRecord::Base
+ validates_presence_of :name
+
+ has_one :user
+
+ def in?
+ !user
+ end
+
+ def out?
+ !!user
+ end
+end
View
@@ -0,0 +1,5 @@
+class User < ActiveRecord::Base
+ validates_presence_of :email
+
+ belongs_to :device
+end
@@ -0,0 +1,22 @@
+<%= form_for(@device) do |f| %>
+ <% if @device.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@device.errors.count, "error") %> prohibited this device from being saved:</h2>
+
+ <ul>
+ <% @device.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing device</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @device %> |
+<%= link_to 'Back', devices_path %>
@@ -0,0 +1,26 @@
+<h1>Listing devices</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Status</th>
+ <th>User</th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @devices.each do |device| %>
+ <tr>
+ <td><%= device.name %></td>
+ <td><%= device.in? ? "In" : "Out" %></td>
+ <td><%= device.user && device.user.email %></td>
+ <td><%= link_to 'Show', device %></td>
+ <td><%= link_to 'Edit', edit_device_path(device) %></td>
+ <td><%= link_to 'Destroy', device, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Device', new_device_path %>
@@ -0,0 +1,5 @@
+<h1>New device</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', devices_path %>
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Name:</b>
+ <%= @device.name %>
+</p>
+
+<p>
+ <b>Status:</b>
+ <%= @device.in? ? "In" : "Out" %>
+</p>
+
+
+<%= link_to 'Edit', edit_device_path(@device) %> |
+<%= link_to 'Back', devices_path %>
Oops, something went wrong.

0 comments on commit 108c98f

Please sign in to comment.