Rails: Multiple Joins with activerecord -


i have model of athlete

athletemodel:

class athlete < user   has_many :videos, :dependent => :destroy   has_many :stats, :dependent => :destroy end 

i trying find videos , stats athlete created_at fields (respectively each association) less or equal week old

since don't know how stats , videos related together, do:

# athlete.rb def get_videos_and_stats   videos = video.where(athlete_id: self, created_at: 1.week.ago..date.today)   stats = stat.where(athlete_id: self, created_at: 1.week.ago..date.today)    [videos, stats] # returns array containing both videos , stats end  # athletes_controller.rb def show   @athlete = athlete.find(params[:id])   # makes 2 instance variables , assign videos , stats them   @videos, @stats = athlete.get_videos_and_stats end  # athletes/show.html.erb <%= render @videos %> <%= render @stats %> 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -