0

I currently have application which allows users to upload an image. Currently. each image belongs to a certain event, or in my case a certain week.

To reduce redundancy and server overload with the same image being uploaded multiple times, I would like to allow the user to upload (1) image and give them the option to assign it to multiple weeks that are load in the database.

Here is the setup now:

Creative Model

 class Creative < ActiveRecord::Base

   belongs_to :week

   mount_uploader :image, CreativeUploader

 end

Week Model

 class Week < ActiveRecord::Base

    has_many :creatives

 end

The issue I am having is getting my application to pass multiple [week_id]'s to a single creative.

Should this be converted to a has_and_belongs_to_many relationship with a join table?

NestedForm

 <%= creative_form.collection_select(:week_id, @campaign.weeks, :id, :start_at) %>

TIA

RubyNewbie
  • 547
  • 5
  • 21

1 Answers1

0

EDIT If it's a many-to-many relationship then your associations will look like this, and yes, you need a new join table.

Creative Model

class Creative < ActiveRecord::Base
  has_and_belongs_to_many :week
  mount_uploader :image, CreativeUploader
end

Week Model

class Week < ActiveRecord::Base
  has_and_belongs_to_many :creatives
end
Alexander
  • 612
  • 1
  • 9
  • 20