Guest User

Untitled

a guest
Sep 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. def index
  2. if (params[:commit])
  3. min = params[:price].match(/.*?(\d+).*?\d+/).captures.first.to_i
  4. max = params[:price].match(/.*?\d+.*?(\d+)/).captures.first.to_i
  5.  
  6. @listings = Listing
  7. @listings = @listings.where(:author => params[:author]) unless params[:author].blank?
  8. @listings = @listings.where(:price => min..max ) unless params[:price].blank?
  9. @listings = @listings.where(:condition => params[:condition]) unless params[:condition].blank?
  10. @listings = @listings.where("created_at > ?", params[:age].to_i.seconds.ago ) unless params[:age].blank?
  11. else
  12. @listings = Listing.all
  13. end
  14.  
  15. respond_to do |format|
  16. format.html # index.html.erb
  17. format.json { render json: @listings }
  18. end
  19. end
  20.  
  21. def manage
  22. if (params[:commit])
  23. min = params[:price].match(/.*?(\d+).*?\d+/).captures.first.to_i
  24. max = params[:price].match(/.*?\d+.*?(\d+)/).captures.first.to_i
  25.  
  26. @listings = Listing.where(:author => current_user.email)
  27. @listings = @listings.where(:author => params[:author]) unless params[:author].blank?
  28. @listings = @listings.where(:price => min..max ) unless params[:price].blank?
  29. @listings = @listings.where(:condition => params[:condition]) unless params[:condition].blank?
  30. @listings = @listings.where("created_at > ?", params[:age].to_i.seconds.ago ) unless params[:age].blank?
  31. else
  32. @listings = Listing.where(:author => current_user.email)
  33. end
  34.  
  35. render :action => "index"
  36.  
  37. end
Add Comment
Please, Sign In to add comment