对于/login
,我的应用程序运行正常,但适用于/login?user="something"
giving 500
我正在使用设计宝石
的routes.rb
devise_for :users, :controllers => { :sessions => 'devise/sessions'}, :skip => [:sessions] do
get '/login' => "devise/sessions#new", :as => :new_user_session
end
错误:
Completed 500 Internal Server Error in 263ms
NoMethodError (undefined method `stringify_keys' for "\"something\"":String):
Rendered /usr/local/rvm/gems/ruby-1.9.2-head/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.6ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-head/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.7ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-head/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (7.9ms)
答案 0 :(得分:1)
stringify_keys
是Rails混合到Ruby Hash类中的一种方法,因此这里的问题是设计期望用户参数中的属性 - 值对的散列而不是普通字符串。换句话说,它期望用户模型对象而不仅仅是用户名。
Rails用于将嵌套属性值对打包成URL查询字符串或HTML格式参数的约定使用方括号,因此您可能需要这样的内容:
/login?user[name]=someone&user[password]=secret