Here’s what I have:
module EventDependencyProperties
def start_date
shows.order('show_date ASC').first.show_date
end
def end_date
shows.order('show_date DESC').first.show_date
end
def is_future_show?
end_date >= Date.today
end
end
class Event < ActiveRecord::Base
include EventDependencyProperties
has_many :shows
has_and_belongs_to_many :users
end
class Show < ActiveRecord::Base
belongs_to :event
end
I have bits of code elsewhere using the is_future_show? method. What I would like to do is have a method in the module mixin to return “future shows” using a query that has the same criteria as the is_future_show? method. How would I go about achieving this? I’m very much a newbie to Rails but tainted by knowledge of other languages and frameworks.
Cheers,
Dany.
You can put the query into a scope:
Call it like this:
Edit: Ah I see. To return all events with a show in the future:
agains this can be scoped:
On a side note, I’m not sure about the setup of your models, especially the use of the mixin. Here’s what I do:
also it would be cleaner if the
show_datecolumn for the Show model was just calleddate(so you could just writeshow.daterather thatshow.show_date).