29d3960a3c
- Remove UUID column from devices table entirely - Update unique index from (owner, uuid) to (owner, token) - Simplify create action to just create device records - Add token-based unregister route for API clients - Consolidate error handling with rescue_from - Update fixtures to remove uuid references Devices are now identified by (owner, token) instead of UUID. This simplifies the client-side registration flow. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
39 lines
869 B
Ruby
39 lines
869 B
Ruby
class Users::DevicesController < ApplicationController
|
|
before_action :set_devices
|
|
|
|
rescue_from ActiveRecord::NotNullViolation, ArgumentError, with: :bad_request
|
|
|
|
def index
|
|
end
|
|
|
|
def create
|
|
@devices.create!(device_params)
|
|
head :created
|
|
end
|
|
|
|
def destroy
|
|
if params[:token].present?
|
|
@devices.destroy_by(token: params[:token])
|
|
head :no_content
|
|
else
|
|
@devices.destroy_by(id: params[:id])
|
|
redirect_to users_devices_path, notice: "Device removed"
|
|
end
|
|
end
|
|
|
|
private
|
|
def set_devices
|
|
@devices = Current.user.devices.order(created_at: :desc)
|
|
end
|
|
|
|
def device_params
|
|
params.permit(:token, :platform, :name).tap do |permitted|
|
|
permitted[:platform] = permitted[:platform].to_s.downcase if permitted[:platform].present?
|
|
end
|
|
end
|
|
|
|
def bad_request
|
|
head :bad_request
|
|
end
|
|
end
|