Skip to content

Instantly share code, notes, and snippets.

@dnordstrom
Created November 26, 2011 18:10
Show Gist options
  • Save dnordstrom/1396063 to your computer and use it in GitHub Desktop.
Save dnordstrom/1396063 to your computer and use it in GitHub Desktop.
Re-gisted!
class DevicesController < ApplicationController
before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy]
def update_registration_id
@device = Device.find_by_device_id(params[:device_id])
@device.registration_id = params[:registration_id]
@device.save
end
# GET /devices
# GET /devices.json
def index
@devices = Device.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @devices }
end
end
# GET /devices/1
# GET /devices/1.json
def show
@device = Device.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @device }
end
end
# GET /devices/new
# GET /devices/new.json
def new
@device = Device.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @device }
end
end
# GET /devices/1/edit
def edit
@device = Device.find(params[:id])
end
# POST /devices
# POST /devices.json
def create
@device = Device.new(params[:device])
@device.user = current_user
respond_to do |format|
if @device.save
format.html { redirect_to @device, notice: 'Device was successfully created.' }
format.json { render json: @device, status: :created, location: @device }
else
format.html { render action: "new" }
format.json { render json: @device.errors, status: :unprocessable_entity }
end
end
end
# PUT /devices/1
# PUT /devices/1.json
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.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @device.errors, status: :unprocessable_entity }
end
end
end
# DELETE /devices/1
# DELETE /devices/1.json
def destroy
@device = Device.find(params[:id])
@device.destroy
respond_to do |format|
format.html { redirect_to devices_url }
format.json { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment