Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class Agent
  2.  
  3. #first try: define this instance method in here
  4. def get_sample_listings
  5. residentials.all(:order => 'RAND()', :limit => 3)
  6. end
  7. end
  8.  
  9. # but, this of course gives me 3 residential listings regardless of whether they have
  10. # photos or not (this is for displaying in the homepage so i dont want to display listings
  11. # with a placeholder
  12.  
  13. #second try and this is where I thought of named_scope but not sure
  14. # how to define it
  15.  
  16. # this is sort of what you suggested
  17. # does not work because is never really residential_id, it can be
  18. # flat_id or land_id
  19.  
  20. def get_sample_listings
  21. residentials.all(:order => 'RAND()', :limit => 3, :conditions => ["photos_residential_id IS NOT NULL")
  22. end
  23. end
  24.  
  25.  
  26. # then i was trying to define a named scope in residential to be able to do
  27. # something like
  28.  
  29. class Agent
  30.  
  31. def get_sample_listingts
  32. residentials.with_photos.random
  33. end
  34.  
  35. end
  36.  
  37.  
  38. # of course, residential is only one part of the class structure, I have 23 classes all up
  39. # so simplifying this as much as i can was in order... only i'm stuck
Add Comment
Please, Sign In to add comment