Rails PaperClip`method_missing':未定义的方法`has_attatched_file'

时间:2015-08-11 00:42:14

标签: ruby-on-rails ruby

我在运行时遇到涉及PaperClip的错误。我按照Paperclip github页面的说明进行操作。涉及回形针的细节如下所述。有什么我可能错过的吗?

错误记录

/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.1.6/lib/active_record/dynamic_matchers.rb:26:in 'method_missing': undefined method 'has_attatched_file' for Vehicle (call 'Vehicle.connection' to establish a connection):Class (NoMethodError)

环境

  • IDE Cloud 9(在Ubuntu上托管的在线IDE)
  • Rails版本:4.1.6
  • Ruby版本:2.1.5p273
  • imagemagick :已安装

vehicle.rb

class Vehicle < ActiveRecord::Base
  has_attatched_file  :main_photo, :styles => { :medium => "300x300>", "thumb" => "100x100>" }, :default_url => "/images/:style/missing.png" 
  validates_attatchment_content_type :main_photo, :content_type => /\Aimage\/.*\Z/   
end

的Gemfile

gem "paperclip", "~> 4.3"

1 个答案:

答案 0 :(得分:1)

你有一个错字的老兄。您需要has_attached_file而不是has_attatched_file

class Vehicle < ActiveRecord::Base
  has_attached_file  :main_photo, :styles => { :medium => "300x300>", "thumb" => "100x100>" }, :default_url => "/images/:style/missing.png" 
  validates_attatchment_content_type :main_photo, :content_type => /\Aimage\/.*\Z/   
end