0

I am attempting to set a Cabinet's Device's attributes to null in a disconnect method. cabinets_controller calls @cabinet.devices.destroy(@device) and that works ok. Before I do that I want to set @device.row_id = nil and @device.position = nil. They are both Fixnum and attr_accesible in the Device model. They are not being altered in the DB when I call this method. Is there a method to call on @device to make this happen?

Thanks.

2
  • 1
    I'm a little confused. Are you trying to update a record right before you destroy it? Commented Apr 1, 2013 at 15:26
  • The destroy method only removes the association. In this instance it removes cabinet_id from the device record. Commented Apr 1, 2013 at 16:11

1 Answer 1

1

I'm guessing that you're trying to break the connection between a @cabinet and a @device without completely deleting the @device. If you're already sure that @device belongs to @cabinet, it might be more straightforward to do something like:

@device.row_id = nil
@device.position = nil
@device.cabinet_id = nil
@device.save!

Basically you'll need to call .save or .save! on @device after setting those other fields to nil; while you're at it you may as well set cabinet_id that way, too.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah yes! I am such a fool. Thanks @sockmonk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.