Rule to use presence belongs_to association
Do you know what to validate for presence if you have belongs_to association: association name or foreign key?
I mean what do you use?:
belongs_to :account
validates :account_id, :presence => true
Or:
belongs_to :account
validates :account, :presence => true
Use second variant!
This is an explanation why: http://railsguides.net/2013/07/11/belongs-to-and-presence-validation-rule1/
Written by Andrey Koleshko
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#