Rails模型类中未定义的方法`validates_attachment_content_type'

时间:2013-05-14 21:13:30

标签: ruby-on-rails ruby gem paperclip undefined

使用Rails 2.3。*(遗留项目,只是添加一些功能),我的回形针插件出错了。我不确定为什么告诉我这个方法是未定义的。当我使用gem list检查我的gem时安装了Paperclip 2.4.5。错误是:

undefined method `validates_attachment_content_type' for #<Class:0x107d4e1c8>

提取的来源(第122行):

119: <%= link_to 'Printable', { :action => 'print', :id => @incident.id }, { :target => '_blank', :class => "button" } %>
120: <% if isviewable?(@incident) %>
121: 
122:   <%= link_to "Pictures (#{@incident.pictures.count})", incident_pictures_path(@incident), :class => "button" %>
123:   <%= link_to "Suspects (#{@incident.suspects.count})", incident_suspects_path(@incident), :class => "button" %>

应用程序跟踪:

/usr/local/rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.11/lib/active_record/base.rb:1998:in `method_missing'
/Users/grantmc/Dev/railsprojects/Police/app/models/picture.rb:5
/Users/grantmc/Dev/railsprojects/Police/app/views/incidents/show.html.erb:122:in `_run_erb_app47views47incidents47show46html46erb'

这是我的Picture模型类(picture.rb): 需要“回形针”

class Picture < ActiveRecord::Base

  validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/pjpeg', 'image/gif','image/bmp']
  validates_attachment_presence :photo, :message => 'is required'

  belongs_to :incident
  belongs_to :user

  has_attached_file :photo,
    :styles => {
      :thumb => "50x50#",
      :small => "150x150>",
      :large => "800x800>",
      :printable => "350x350"
    }

end

0 个答案:

没有答案