Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validates_presence_of behaves different in Rails5 #454

Open
gudata opened this issue Sep 12, 2016 · 0 comments
Open

validates_presence_of behaves different in Rails5 #454

gudata opened this issue Sep 12, 2016 · 0 comments

Comments

@gudata
Copy link

gudata commented Sep 12, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant