0
我得到的方法是我的Rails项目中的未定义错误。该方法由插件回形针使用。谁能告诉我我做错了什么?这里是我的图片类的开头:未定义的回形针方法
要求 “回形针”
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
...
这里是我的错误:
Extracted source (around line #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" %>
Application trace:
/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'
因此,在这种情况下,我需要用'attr_accesor:photo'在我的模型? – grantmcconnaughey 2013-05-14 17:03:47
是的,您必须在模型中添加attr_accesor:photo – sunny1304 2013-05-14 17:05:47
不幸的是,添加该行代码会产生完全相同的错误。该错误消息使我相信,由于某种原因,该模型无法“看见”回形针插件,因为它无法识别validates_attachment_content_type方法。 – grantmcconnaughey 2013-05-14 18:26:39