Ask for Help
“How can I validate the presence of a boolean field?”
false.present? is false, so validates :a_boolean_field, presence: true will not cause a validation error when the field’s value is false. What you’re really trying to do, probably, is to validate that it’s not nil.
The best solution we had was to use validates :a_boolean_field, inclusion: { in: [true, false], message: "must be specified" }. The custom message is needed because the default inclusion message looks weird to the user here.
How can we integration-test CarrierWave uploads to S3? Can we stub out S3?
Two suggestions: use VCR to mock the S3 conversation or use Park Place to provide a fake S3 and check the results afterwards.
Interesting Things
Given a Rails
belongs_toassociation reflection, how do you get the name of the foreign key column? It’s not what you might think:class Person < ActiveRecord::Base belongs_to :best_friend, class_name: "Person" end Person.reflect_on_association(:best_friend).primary_key_name # => "best_friend_id"Why is it called
primary_key_nameif it’s a foreign key? No idea. But it is.Note: The reflection also has an
association_foreign_key. This is not what it’s for. In this case, for instance,Person.reflect_on_association(:best_friend).association_foreign_key # => "person_id"