Do what Dan Reedy said and use the hidden_field_tag ββfile in your form.
I am worried about this line in the controller creation method:
@device.rfids << Rfid.where('rfid_tag' => params[:rfid_tag]).first
Itβs good if your rfid also has many devices, so you have a lot of different relationships. If the rfid tag comes with just one device, although you may have to change it to something like:
rfid = Rfid.where('rfid_tag' => params[:rfid_tag]).first rfid.device_id = @device.id rfid.save!
And, of course, do not forget to handle cases when case_id or rfid_tag ββare not found in the database, which you get from the params hash. He can never count on the input entered by the user to be valid or correspond to the real records, even if he is hidden from the fields.
source share