47
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

undefined method ***_pathの解決策

Last updated at Posted at 2019-07-04

学習の記録 :writing_hand_tone4:

***/edit.html.erb
<%= form_for @*** do |f| %>
  # 省略
<% end %>
NoMethodError undefined method `***_path'

が出てしまう現象が発生。
ルーティングを確認してもパスは合っている・・なぜ :sweat:

##原因

form_forが自動的に生成してくれるパスは複数形のみらしい。

$ rails routes
  # resourcesが生成してくれたroutes
  edit_admins_単数形 GET    /admins/複数形/new(.:format)

  # form_forが欲しかったroutes
  edit_admins_複数形 POST   /admins/複数形/new(.:format)

##解決法

urlを指定して、こっちに飛ぶんだよ〜と教えてあげる :fist_tone4:

***/edit.html.erb
<%= form_for @hoge, url: ***_index_path do |f| %>
  # 省略
<% end %>

47
36
1

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
47
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?