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'
4

1 回答 1

0

您的模型中缺少attr_accessible您。

回形针有一些不属于您的模型的属性,因此您必须 attr_accessorattr_accessor :attach

于 2013-05-14T16:59:27.960 回答