spree-contrib / spree-multi-domain

Multiple Spree stores on different domains - single unified backed for processing orders
https://guides.spreecommerce.org
194 stars 191 forks source link

Paperclip::Errors::MissingRequiredValidatorError in Spree::Admin::StoresController#update #155

Open W0lfbane opened 8 years ago

W0lfbane commented 8 years ago

Trying to add a new logo for a domain. I am using stable build 3.1. Whenever I attempt to add a logo, I get this error:

Paperclip::Errors::MissingRequiredValidatorError in Spree::Admin::StoresController#update

Extracted source (around line #400):              
    def ensure_required_validations!
      if missing_required_validator?
        raise Paperclip::Errors::MissingRequiredValidatorError
      end
    end

A previous issue submitted by a user shows that adding a validation to store_decorator.rb fixes the problem, however it looks like that already exists in my case:

module Spree
  Store.class_eval do
    has_and_belongs_to_many :products, join_table: 'spree_products_stores'
    has_many :taxonomies
    has_many :orders

    has_many :store_payment_methods
    has_many :payment_methods, through: :store_payment_methods

    has_many :store_shipping_methods
    has_many :shipping_methods, through: :store_shipping_methods

    has_and_belongs_to_many :promotion_rules, class_name: 'Spree::Promotion::Rules::Store', join_table: 'spree_promotion_rules_stores', association_foreign_key: 'promotion_rule_id'

    has_attached_file :logo,
      styles: { mini: '48x48>', small: '100x100>', medium: '250x250>' },
      default_style: :medium,
      url: 'stores/:id/:style/:basename.:extension',
      path: 'stores/:id/:style/:basename.:extension',
      convert_options: { all: '-strip -auto-orient' }

    if respond_to? :logo_file_name
      validates_attachment_file_name :logo, matches: [/png\Z/i, /jpe?g\Z/i]
    end

  end
end

What am I doing wrong?

visoft commented 7 years ago

This can be fixed by just including validates_attachment and adding a migration for logo_content_type to the Spree::Store model.

Migration

class AddLogoContentTypeForStore < ActiveRecord::Migration
  def change
    add_column :spree_stores, :logo_content_type, :string
  end
end

store_decorator.rb

Spree::Store.class_eval do
  validates_attachment :logo, content_type: { content_type: %w(image/jpeg image/jpg image/png image/gif) }
end