I am having a problem while validating on an image field in model on a rails4 app.
class ModelA < ActiveRecord::Base
validates :name, presence: true
validates :logo, presence: true
has_attached_file :logo, styles: {
thumb: '100x100>',
square: '200x200#'
}
In the migrations, a new instance of this model is to be created.
def migrate(direction)
super
if direction == :up
obj = Model1.create!(:name => "Test")
This is failing as the required field is not specified and If I am explicitly specifying a default image, then the table does not have the necessary column yet.
This migration runs if I am removing the image (in this case, logo) validation before migration and thereafter specify the image file and details like its name. Is there a better way to setup this model?