Working with existing Devise


(Ryan Heneise) #21

I have done this but it’s giving me validation errors:

(byebug) @node.errors.full_messages
["Creator must exist", "Updater must exist"]

(Ryan Heneise) #22

Solution is to add optional: true to the belongs_to relationship in node.rb:

belongs_to :creator, class_name: 'PushType::User', optional: true
belongs_to :updater, class_name: 'PushType::User', optional: true

(Ryan Heneise) #23

It appears that with Rails > 5, the belongs_to association is required by default. See https://blog.bigbinary.com/2016/02/15/rails-5-makes-belong-to-association-required-by-default.html

I added the following to an initializer, and it cleared up the validation error:

Rails.application.config.active_record.belongs_to_required_by_default = false

(Aaron Russell) #24

Thanks for highlighting this. I’ve raised an issue to add optional: true to the user relationships:

https://github.com/pushtype/push_type/issues/48