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
|
||||
skip_forgery_protection
|
||||
allow_unauthenticated_access
|
||||
|
||||
def create
|
||||
identifier = params.expect(:identifier)
|
||||
rfid_tag = RfidTag.find_or_initialize_by(identifier:)
|
||||
rfid_tag_params = params.expect(rfid_tag: [ :chip_id, :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?
|
||||
register rfid_tag
|
||||
return
|
||||
|
|
@ -15,6 +16,7 @@ class RfidTagsController < ApplicationController
|
|||
private
|
||||
|
||||
def register(rfid_tag)
|
||||
rfid_tag.user = RfidTag.where(chip_id: rfid_tag.chip_id).first&.user
|
||||
rfid_tag.save!
|
||||
head :created, code: :registered
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue