0
我到處搜索,根本找不到解決方案。這裏是我的問題:「頁面文件夾Rails:未定義的方法`image'爲零:NilClass
在‘
在我的「意見」的文件夾,我有「針」和視圖/銷/’,我創建了一個名爲」 _pin.html.erb 「和裏面,我寫了這個:
<%= image_tag pin.image(:medium) %>
我們在我的‘意見/頁’文件夾,我的文件名爲‘home.html.erb’和裏面,我試圖呈現的代碼」 _pin.html.erb「使用此:
<%= render "pins/pin" %>
但我得到這個錯誤r:
undefined method `image' for nil:NilClass
Extracted source (around line #1):
<%= image_tag pin.image(:medium) %>
那麼,會出現什麼問題?我使用回形針,我試圖呈現相同的代碼「視圖/銷/ index.html.erb使用此:
<%= render @pins %>
,它是完美的,但在渲染」視圖/頁/ home.html做爲.erb」!?(如上所述)文件,我收到提示
任何人都可以幫助我
在我的 「模型/ 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
我盡力解釋我的問題,請告訴我,米做錯了嗎?謝謝。
謝謝!問題解決了! :) –