Question

I have models in my application for Festivals and Submissions. Each submission belongs to a single festival. And I have a helper to determine what is the "current_festival" based on dates for each festival.

module ApplicationHelper

  def current_festival
    @current_festival ||= Festival.current.first
  end

end

.current is a scope in the festival model:

  scope :current, where("published = true and closing_date >= ?", Time.now.to_date).order('closing_date asc').limit(1)

What I'd like is to restrict the submissions shown in the index view to ones that belong to the current festival only. How would you do that in the controller? Or would it be best to somehow do that in the model, perhaps through a scope?

Was it helpful?

Solution

I suppose you have a relation defined like this:

class Festival
  has_many :submissions
end

Then you can do in any place:

Festival.current.submissions
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top