0
votes

using the paperclip gem i want to validate the production part when someone uploads a image.It works in development but not in production mode

class Listing < ActiveRecord::Base
  if Rails.env.development?

    has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
    validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)

  else

    has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
    validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)

        :storage => :dropbox,
        :dropbox_credentials => Rails.root.join("config/dropbox.yml")
        :path => ":style/:id_:filename"

    end
end

getting error

/etsydemo2014/app/models/listing.rb:12: syntax error, unexpected =>, expecting keyword_end :storage => :dropbox, ^ /Users/neilpatel/Desktop/Rails/etsydemo2014/app/models/listing.rb:13: syntax error, unexpected ',', expecting keyword_end

1
What error are you getting? - Pavan
/Users/neilpatel/Desktop/Rails/etsydemo2014/app/models/listing.rb:12: syntax error, unexpected =>, expecting keyword_end :storage => :dropbox, ^ /Users/neilpatel/Desktop/Rails/etsydemo2014/app/models/listing.rb:13: syntax error, unexpected ',', expecting keyword_end - Neil
Can't you see, you didn't make the arguments as comma separated ? - Arup Rakshit

1 Answers

3
votes

You are missing comma at end of validation. Thus, practically you were not adding any of those remaining constraints. Change that to :

has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png), :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :path => ":style/:id_:filename"

Notice the comma at end of content_type key which is preceded by storage.