Running this in a migration worked. Column wasn't added.
def up
change_table :images do |t|
t.references :event
end
end
Question
I'm creating a site that has events. Each event acts as a gallery and has_many
images. Each image belongs_to
and event.
I followed the RailsCast #253 CarrierWave gem. When I try to add a new image, it says
undefined method `event_id' for # Image:0x7302438
<%= form_for @image, :html => {:multipart => true} do |f| %>
<%= f.error_messages %>
<%= f.hidden_field :event_id %>
<%= f.label :title %><br />
<%= f.text_field :title %>
Here is my 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
and the 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
Solution
Running this in a migration worked. Column wasn't added.
def up
change_table :images do |t|
t.references :event
end
end