dragonfly icon indicating copy to clipboard operation
dragonfly copied to clipboard

validates_presence_of behaves different in Rails5

Open gudata opened this issue 8 years ago • 0 comments

In order to make the validate_presence_of to work you have to remove manually the params if they are blank. If you don't remove them, attachment is created.

model:

class Asset < ActiveRecord::Base
  belongs_to :assetable, polymorphic: true, touch: true
  dragonfly_accessor :data
  validates_presence_of :data
end

controller:

    def assets_params
      cleaned_permitted_params = params[:asset].permit([
        :name,
        :data,
        :retained_data,
        ])

      cleaned_permitted_params.delete(:data) if cleaned_permitted_params[:data].blank?
      cleaned_permitted_params.delete(:retained_data) if cleaned_permitted_params[:retained_data].blank?
      cleaned_permitted_params
    end

gudata avatar Sep 12 '16 09:09 gudata