Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Agent
- #first try: define this instance method in here
- def get_sample_listings
- residentials.all(:order => 'RAND()', :limit => 3)
- end
- end
- # but, this of course gives me 3 residential listings regardless of whether they have
- # photos or not (this is for displaying in the homepage so i dont want to display listings
- # with a placeholder
- #second try and this is where I thought of named_scope but not sure
- # how to define it
- # this is sort of what you suggested
- # does not work because is never really residential_id, it can be
- # flat_id or land_id
- def get_sample_listings
- residentials.all(:order => 'RAND()', :limit => 3, :conditions => ["photos_residential_id IS NOT NULL")
- end
- end
- # then i was trying to define a named scope in residential to be able to do
- # something like
- class Agent
- def get_sample_listingts
- residentials.with_photos.random
- end
- end
- # of course, residential is only one part of the class structure, I have 23 classes all up
- # so simplifying this as much as i can was in order... only i'm stuck
Add Comment
Please, Sign In to add comment