Subrat Rout
Subrat Rout

Reputation: 95

Showing one video for a product out of several videos in a rails app

In my rails app, I have a product category. Each product can have multiple videos(from Youtube or vimeo).

I have generated a model and migration with following columns

:title, :description, :video_link, :product_id

I would like to show only one video on the product display page as a main or primary video and the rest videos on "details on product" page.

/product.rb

has_many :video_links, dependent: :destroy

/video_link.rb

 belongs_to :product

So my question is, how should I approach to mark one video to display on the product front page (view) and the rest videos for details page?

Upvotes: 0

Views: 44

Answers (2)

Mori
Mori

Reputation: 27789

how should I approach to mark one video to display on the product front page (view) and the rest videos for details page?

That depends on what you want a "front page video" to mean.

  • An editorial decision: add a boolean column for 'featured' or 'front page', and let the editorial decision makers flip that flag at will. You could either have other code to make it unique, or add a date and take the latest of the featured videos.
  • The hottest video: keep track of views or votes per video, and display the latest one with the maximum view/vote count on the front page.
  • The latest video: add an updated_at column and pick the video with the largest value.
  • etc.

In other words it looks like at this stage this is a design rather than a coding issue.

Upvotes: 1

timtyrrell
timtyrrell

Reputation: 19

You can have another column that is something like "main_video" on the "video_links" table that is a boolean and just display that one whenever you need to grab just one.

Upvotes: 1

Related Questions