register rfid tag with chip id
This commit is contained in:
parent
71aaa32d15
commit
7fbc41d332
1 changed files with 4 additions and 2 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
class RfidTagsController < ApplicationController
|
class RfidTagsController < ApplicationController
|
||||||
skip_forgery_protection
|
skip_forgery_protection
|
||||||
|
allow_unauthenticated_access
|
||||||
|
|
||||||
def create
|
def create
|
||||||
identifier = params.expect(:identifier)
|
rfid_tag_params = params.expect(rfid_tag: [ :chip_id, :identifier ])
|
||||||
rfid_tag = RfidTag.find_or_initialize_by(identifier:)
|
rfid_tag = RfidTag.find_or_initialize_by(chip_id: rfid_tag_params[:chip_id], identifier: rfid_tag_params[:identifier])
|
||||||
if rfid_tag.new_record?
|
if rfid_tag.new_record?
|
||||||
register rfid_tag
|
register rfid_tag
|
||||||
return
|
return
|
||||||
|
|
@ -15,6 +16,7 @@ class RfidTagsController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def register(rfid_tag)
|
def register(rfid_tag)
|
||||||
|
rfid_tag.user = RfidTag.where(chip_id: rfid_tag.chip_id).first&.user
|
||||||
rfid_tag.save!
|
rfid_tag.save!
|
||||||
head :created, code: :registered
|
head :created, code: :registered
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue