What is `stringify_keys' in rails and how to solve it when this error comes

寵の児 提交于 2019-12-04 06:22:11

1) stringify_keys is a method that is called on a hash to convert its keys from symbols to strings. It's added by Rails - it's not a standard Ruby method. Here it is in the docs.

{:a => 1, :b => 2}.stringify_keys # => {"a" => 1, "b" => 2}

2) This means that your code is passing "/users/sign_in" somewhere that is expecting a hash. Closer inspection reveals that you are mixing and matching two forms of link_to:

# specify link contents as an argument
link_to "The text in the link", "/path/to/link", some: "options"

# specify link contents in a block
link_to "/path/to/link", some: "options" do
  "The text in the link"
end

As you can see you are trying to do both:

<%= link_to "Sign out", destroy_user_session_path, :method => 'delete' do %>
  <i class=" icon-user icon-black"></i> 
<% end %>

and Rails expects the second argument in the block form to be the options hash, so it is calling stringify_keys on it which is causing your error.

Change those links to look like this instead:

<%= link_to destroy_user_session_path, :method => 'delete' do %>
  <i class=" icon-user icon-black"></i> Sign out 
<% end %>

as per the documentat stringify_keys will try to convert all keys to a string. So in simple works the method expects something with key values and convert its keys to strings.

In your case most probably your User object could be empty or a plan string. is this doesnot work try posting the complete error log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!