@video = Video.find(params[:id])
Video has a parameter called description. I would like to get a subset of @video where :description is empty. I'm sure there's an inline .each type statement that would do it but have no idea how.
Thanks
For starters, in your example code you're only retrieving one record. To retrieve all records, you'd have to call:
@videos = Video.all
To get a subset, it depends how you want to do it. You can either do it when you're querying the database:
# Rails 2
@videos = Video.find(:all, :conditions => ['description = ? OR description IS NULL', ''])
# Rails 3
@videos = Video.where('description = ? OR description IS NULL', '')
Or, you could partition your @videos array using a Ruby method:
# Find all our videos
@videos = Video.all
# And then pick the ones where the description attribute is blank
@videos_with_blank_description = @videos.select { |v| v.description.blank? }
Array#select is a method in Enumerable which iterates through an array and returns the elements where the block argument evaluates to True:
http://www.ruby-doc.org/core/classes/Enumerable.html#M001488