hello_world_controller.rb 959 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. results = (1..queries).map do
  8. # get a random row from the database, which we know has 10000
  9. # rows with ids 1 - 10000
  10. World.find(Random.rand(10000) + 1)
  11. end
  12. render :json => results
  13. end
  14. def fortune
  15. @fortunes = Fortune.all
  16. @fortunes << Fortune.new(:message => "Additional fortune added at request time.")
  17. @fortunes = @fortunes.sort { |x, y| x.message <=> y.message }
  18. end
  19. def update
  20. queries = (params[:queries] || 1).to_i
  21. results = (1..queries).map do
  22. # get a random row from the database, which we know has 10000
  23. # rows with ids 1 - 10000
  24. world = World.find(Random.rand(10000) + 1)
  25. world.randomNumber = Random.rand(10000) + 1
  26. world.save
  27. world
  28. end
  29. render :json => results
  30. end
  31. end