我正在创建一个有事件的网站。每个事件都充当画廊和has_many
图像。每个图像belongs_to
和事件。
我关注了RailsCast #253 CarrierWave gem。当我尝试添加新图像时,它说
# Image:0x7302438 的未定义方法“event_id”
<%= form_for @image, :html => {:multipart => true} do |f| %>
<%= f.error_messages %>
<%= f.hidden_field :event_id %>
<%= f.label :title %><br />
<%= f.text_field :title %>
这是我的 image.rb
class Image < ActiveRecord::Base
attr_accessible :event_id, :title, :image
validates :title, :image, :presence => :true, :uniqueness => :true
belongs_to :event
mount_uploader :image, ImageUploader
end
和 event.rb
class Event < ActiveRecord::Base
attr_accessible :title, :date, :about
validates :title, :about, :date, :presence => :true
validates :title, :uniqueness => :true
has_many :images
extend FriendlyId
friendly_id :title, use: [:slugged, :history]
end