Guest User

Untitled

a guest
Jun 26th, 2018
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. class UsersController
  2. def create
  3. @user = User.new(params[:user])
  4. respond_to do |format]
  5. if @user.save ...
  6. else
  7. format.json ....
  8. end
  9. end
  10. end
  11.  
  12. Error occurred while parsing request parameters.
  13. Contents:
  14.  
  15. user: {login: "John", email: "john@yahoo.com", password: "111"}}
  16. /! FAILSAFE /! Mon Nov 08 02:01:04 -0800 2010
  17.  
  18. Status: 500 Internal Server Error
  19. Invalid JSON string
  20. c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/json/backends/yaml.rb:14:in `decode'
  21. c:1:in `__send__'
  22. c:1:in `decode'
  23. c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:42:in `parse_formatted_parameters'
  24. c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:11:in `call'
  25. c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call'
  26. c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call'
  27. c:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
  28. c:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
  29. c:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
  30. c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in `call'
  31. c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:34:in `run'
  32. c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call'
  33. c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/static.rb:31:in `call'
  34. c:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
  35. c:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
  36. c:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
  37. c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/log_tailer.rb:17:in `call'
  38. ...
  39. c:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in `run'
  40. c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
  41. c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
  42. c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
  43. script/server:3
  44. re.rb:31:in `require'
  45. script/server:3
  46.  
  47. begin
  48. format.json
  49. rescue ParseError => e
  50. render :text => "Now there's some ugly JSON! (#{e.message})", :status => 500
  51. end
  52.  
  53. class UsersController < ApplicationController
  54. ...
  55. rescue_from ParseError do |e|
  56. render ...
  57. end
  58. ...
  59. end
  60.  
  61. def decode(json)
  62. if json.respond_to?(:read)
  63. json = json.read
  64. end
  65. YAML.load(convert_json_to_yaml(json))
  66. rescue ArgumentError
  67. raise ParseError, "Invalid JSON string"
  68. end
Add Comment
Please, Sign In to add comment