hello_world_controller.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. class HelloWorldController < ApplicationController
  2. def json
  3. render :json => {:message => "Hello, World!"}
  4. end
  5. def db
  6. queries = (params[:queries] || 1).to_i
  7. if queries > 1
  8. results = (1..queries).map do
  9. # get a random row from the database, which we know has 10000
  10. # rows with ids 1 - 10000
  11. World.find(Random.rand(10000) + 1)
  12. end
  13. else
  14. results = World.find(Random.rand(10000) + 1)
  15. end
  16. render :json => results
  17. end
  18. def fortune
  19. @fortunes = Fortune.all
  20. @fortunes << Fortune.new(:id => 0, :message => "Additional fortune added at request time.")
  21. @fortunes = @fortunes.sort_by { |x| x.message }
  22. end
  23. def update
  24. queries = (params[:queries] || 1).to_i
  25. results = (1..queries).map do
  26. # get a random row from the database, which we know has 10000
  27. # rows with ids 1 - 10000
  28. world = World.find(Random.rand(10000) + 1)
  29. world.randomNumber = Random.rand(10000) + 1
  30. world.save
  31. world
  32. end
  33. render :json => results
  34. end
  35. end