2013-05-14 74 views
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' 

回答

0

你在你的模型丟失attr_accessible

回形針有一些屬性,是不是你的模型的一部分,所以你必須明確地ASIGN attr_accessor他們喜歡attr_accessor :attach

+0

因此,在這種情況下,我需要用'attr_accesor:photo'在我的模型? – grantmcconnaughey 2013-05-14 17:03:47

+0

是的,您必須在模型中添加attr_accesor:photo – sunny1304 2013-05-14 17:05:47

+0

不幸的是,添加該行代碼會產生完全相同的錯誤。該錯誤消息使我相信,由於某種原因,該模型無法「看見」回形針插件,因爲它無法識別validates_attachment_content_type方法。 – grantmcconnaughey 2013-05-14 18:26:39

相關問題