I have a model class movie and I was asked to select one random object to show it as featured on the index. This should be a class method
class Movie < ApplicationRecord
belongs_to :user
has_many :reviews, dependent: :destroy
has_many :users, through: :reviews
validates :description, :movie_length, :director, :rating, presence: true
validates :title, presence: true , uniqueness: true
def self.most_recent
order('created_at DESC')
end
#randondly select a movie onject to disply that on the page.
def self.featured
self.where('title').sample
end
end
And I need to call this on index
def index
@movies = Movie.all
end
This is on rails. any ideas?