Skip to content

Instantly share code, notes, and snippets.

@alainbloch
Created July 1, 2010 21:41
Show Gist options
  • Save alainbloch/460612 to your computer and use it in GitHub Desktop.
Save alainbloch/460612 to your computer and use it in GitHub Desktop.
diff --git a/app/controllers/xp/base_controller.rb b/app/controllers/xp/base_controller.rb
index 1116745..2ee4eec 100644
--- a/app/controllers/xp/base_controller.rb
+++ b/app/controllers/xp/base_controller.rb
@@ -6,12 +6,12 @@ class Xp::BaseController < ApplicationController
def current_device
return @current_device if defined?(@current_device)
- @current_device = current_user.try(:device) || Xp::Device.find_by_id( session[:device_id] || params[:id] )
+ @current_device = current_user.try(:device) || Xp::Device.find_by_id( session[:device_id] || params[:device_id] )
end
def current_platform
return @current_platform if defined?(@current_platform)
- @current_platform = current_device.try(:platform) || (params.has_key?(:platform) && Xp::Platform.find_by_identifier(params[:platform]))
+ @current_platform = current_device.try(:platform) || Xp::Platform.find_by_identifier(params[:platform])
end
def device_required
diff --git a/app/controllers/xp/devices_controller.rb b/app/controllers/xp/devices_controller.rb
index a84857f..665a747 100644
--- a/app/controllers/xp/devices_controller.rb
+++ b/app/controllers/xp/devices_controller.rb
@@ -16,7 +16,7 @@ class Xp::DevicesController < Xp::BaseController
@current_device = current_platform.devices.create(params[:device])
respond_to do |format|
if @current_device.valid?
- format.json { head :ok }
+ format.json { head :created }
else
format.json { render :json => @current_device.errors.full_messages.to_json, :head => :bad_request }
end
@@ -31,8 +31,9 @@ class Xp::DevicesController < Xp::BaseController
# Params:
# @identifier (string)
def show
+ @current_device = XP::Device.find_by_identifier(params[:id])
respond_to do |format|
- if current_device
+ if @current_device
format.json { head :ok }
else
format.json { head :not_found }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment