LoginSignup
66
55

More than 5 years have passed since last update.

link_toメソッドでブロック使おうとしたら"undefined method `stringify_keys' for"ってエラーが出る

Posted at
link_to 'hoge', fuga_path, class: 'foo' do
  %span.bar
end

みたいに書いたら"undefined method `stringify_keys' for"ってエラーが出た

結論としては以下のように書くと解決

link_to fuga_path, class: 'foo' do
  %span.bar
end

link_to(name = nil, options = nil, html_options = nil, &block)

link_to(body, url, html_options = {})
  # url is a String; you can use URL helpers like
  # posts_path

link_to(body, url_options = {}, html_options = {})
  # url_options, except :method, is passed to url_for

link_to(options = {}, html_options = {}) do
  # name
end

link_to(url, html_options = {}) do
  # name
end

って書いてあって、nameとurlを両方使ってる場合はブロックは取れないっぽい。

You can use a block as well if your link target is hard to fit into the name parameter.

ってリファレンスに書いてあるし、nameの代用としてブロックを使っているので当然っちゃ当然なのか

66
55
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
66
55