Template Error in Form_for in Rails

I have a student in a nested model that refers to high_school. The problem is that when I go to create a new student (/ high_schools / 1 / students / new), I get this error:

No route matches {:action=>"destroy", :controller=>"students", :high_school_id=> # <HighSchool id: 1, name: "cool place", ... }

<%= form_for @student, :url => high_school_student_path(@high_school, @student), :html => { :multipart => true } do |f| %>

I think I'm just doing something very simple and stupid that I can't think of.

My environment: Rails3 and Ruby1.9.2dev

Thank!

+3
source share
2 answers

Try passing the array as the first arg for form_for, and remove the hash: url.

<%= form_for [@high_school, @student], :html => { :multipart => true } %>

And make sure @student is a new entry.

+1
source

Maybe add

delete 'student' => :destroy

in routes.rb

: students

     delete 'student' => :destroy

end

0
source

Source: https://habr.com/ru/post/1737845/


All Articles