Ruby on rails Rails:未定义的方法`image';零级:零级

Ruby on rails Rails:未定义的方法`image';零级:零级,ruby-on-rails,Ruby On Rails,我到处找,根本找不到解决办法。我的问题是: 在我的“视图”文件夹中,我有“PIN”和“页面”文件夹 在“views/pins/”中,我创建了一个名为“_pin.html.erb”的文件,并在其中编写了以下内容: <%= image_tag pin.image(:medium) %> 现在,在我的“views/pages”文件夹中,我有一个名为“home.html.erb”的文件,在它里面,我尝试使用以下方法呈现“_pin.html.erb”的代码: <%= render

我到处找,根本找不到解决办法。我的问题是:

在我的“视图”文件夹中,我有“PIN”和“页面”文件夹

在“views/pins/”中,我创建了一个名为“_pin.html.erb”的文件,并在其中编写了以下内容:

<%= image_tag pin.image(:medium) %>

现在,在我的“views/pages”文件夹中,我有一个名为“home.html.erb”的文件,在它里面,我尝试使用以下方法呈现“_pin.html.erb”的代码:

<%= render "pins/pin" %>
<%= render @pins %>

但我得到了一个错误:

undefined method `image' for nil:NilClass 
Extracted source (around line #1):
<%= image_tag pin.image(:medium) %>
nil:NilClass的未定义方法“image” 提取的源(第1行附近): 那么,问题出在哪里呢?我正在使用回形针,并尝试在“views/pins/index.html.erb”中使用以下代码呈现相同的代码:

<%= render "pins/pin" %>
<%= render @pins %>

它呈现得非常完美,但在“views/pages/home.html.erb”文件中(如上所述),我发现了一个错误

有人能帮我吗

在我的“models/pin.rb”文件中,我有以下内容:

class Pin < ActiveRecord::Base
  attr_accessible :description, :image

  validates :description, presence: true

  belongs_to :user
  has_attached_file :image
  validates :user_id, presence: true
  validates_attachment :image, presence: true,
                        content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']},
                        size: { less_than: 5.megabytes}
  has_attached_file :image, styles: { medium: "320x240"}
end
class Pin

我尽力解释我的问题,请告诉我我做错了什么?谢谢。

使用
render@pins
时,Rails会自动将每个
pin
传递到您的收藏中。 如果要使用partial,则必须提供要使用的集合,如下所示:

<%= render partial: 'pins/pin', collection: @pins %>