So I am working on an application where I want to display a video on the main page of the site. The video model has an actual_date and public_filename attribute. Now a user sets the actual date as :date in the model. I am trying to figure out how to best go about making the video on the homepage display the video that is assigned to today’s date. My homepage view is:
Please wait while the video loads…
<script type='text/javascript'>
var s1 = new SWFObject('/flash/player.swf','player','500','372','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=<%= current_video.public_filename %>');
s1.write('preview');
</script>
I just included the current_video method, as I was playing around with creating one to return to the view with the right video url.
So I need a way to look at all of the videos in the database, see if any of the actual_date attributes are equal to today’s date and if so tell current_video that it equals that video.
Thank you for any input or suggestions you might have!
You don’t specify what should happen if more than one video has an actual_date that is equal to today’s date. However, to retrieve one video just do:
—or you can do:
Whether you use
firstorlastwill depend on if you have some secondary sort order set up on yourVideomodel. If it were me I’d create a named scope for this:—then you can do