期待关键词时出错

时间:2016-03-09 12:06:44

标签: ruby-on-rails

在期待关键字时出错

class Listing < ActiveRecord::Base

  if Rails.env.development?
    has_attached_file :image, :styles => { :medium => "200", :thumb => "100x100>" }, :default_url => "default.jpg"
    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
  else
    has_attached_file :image, :styles => { :medium => "200", :thumb => "100x100>" }, :default_url => "default.jpg",
    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
                :storage => :dropbox,
                :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
                :path => ":style/:id_filename"
  end


  validates :name, :description, :price, :address, :phone, presence: true 
  validates :price, numericality: { greater_than: 0}
  validates :phone, length: { maximum: 14 }

  validates_attachment_presence :image
  belongs_to :user
end

1 个答案:

答案 0 :(得分:1)

行尾的额外逗号

has_attached_file :image, :styles => { :medium => "200", :thumb => "100x100>" }, :default_url => "default.jpg",

在行尾没有逗号

validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

希望这可能对你有帮助.....

class Listing < ActiveRecord::Base

  if Rails.env.development?
    has_attached_file :image, :styles => {:medium => "200", :thumb => "100x100>"}, :default_url => "default.jpg"
    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
  else
    has_attached_file :image, :styles => {:medium => "200", :thumb => "100x100>"}, :default_url => "default.jpg"
    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/,
                                      :storage => :dropbox, :dropbox_credentials => Rails.root.join("config/dropbox.yml"), :path => ":style/:id_filename"

  end

  validates :name, :description, :price, :address, :phone, presence: true
  validates :price, numericality: {greater_than: 0}
  validates :phone, length: {maximum: 14}

  validates_attachment_presence :image
  belongs_to :user

end