の行にstudents_controller対応するがあります。これにより、 likeおよび。という単語を使用するルートが作成されます。を使用する場合、URLはオブジェクトクラスから決定されます。この場合、は、オブジェクトが新しいレコードであり、オブジェクトが永続化されているときのパスになります。定義されていないため、このエラーを修正するには、のURLを手動で設定する必要がありますresources :studentsroutes.rbstudentsstudents_pathnew_student_pathform_for(@record)@recordUserusers_pathuser_path(@record)users_controllerform_for
form_for @user, url: student_path(@user), html: { method: :put } do |f|
ここで、部分呼び出し_form.html.erbを使用していて、これを新規アクションと編集アクションの両方で使用する場合、新規アクションと編集アクションの両方のURLが異なるため、問題が発生します。ビューを次のように変更する必要があります
# new.html.erb
form_for @user, url: students_path, html: { method: :post } do |f|
render 'form', f: f
# edit.html.erb
form_for @user, url: student_path(@user), html: { method: :put } do |f|
render 'form', f: f
# _form.html.erb
f.text_field :name
f.text_field :title