Advertisement
Guest User

Untitled

a guest
May 30th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. def self.search(agent, params)
  2. RealPropertySale.where(id: available_ids)
  3. .joins(:address)
  4. .by_state(state)
  5. .by_suburb(suburb)
  6. .by_post_code(post_code)
  7. .by_country(country)
  8. .paginate(page: page)
  9. end
  10.  
  11. def self.by_state(state)
  12. where(addresses: {state: state})
  13. end
  14.  
  15. def self.by_suburb(suburb)
  16. where(addresses: {suburb: suburb})
  17. end
  18.  
  19. def self.by_post_code(post_code)
  20. where(addresses: {post_code: post_code})
  21. end
  22.  
  23. def self.by_country(country)
  24. where(addresses: {country: country})
  25. end
  26.  
  27. def self.by_state(state)
  28. return current_scope if state.nil?
  29. where(addresses: {state: state})
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement