Rails3 - How to create a submit button for a nested resource

I am using SimpleForm in Rails 3. How do I create a submit button for this attached resource?

resources :schools do resources :students end <%= simple_form_for @student do |f| %> <%= f.input :first_name %> <%= f.input :last_name %> <%= f.button :submit %> <% end %> 

If I use f.submit :

 ActionView::Template::Error (undefined method `students_path' for #<#<Class:0x000001040ddfb8>:0x000001040d2578>): 1: <%= simple_form_for @student do |f| %> 2: <%= f.input :first_name %> 3: <%= f.input :last_name %> 4: <%= f.submit %> 
+4
source share
3 answers

The correct code to represent is:

 <%= simple_form_for [@school, @student] do |f| %> <%= f.input :first_name %> <%= f.input :last_name %> <%= f.button :submit %> <% end %> 
+16
source

Just use <%= f.submit %> instead of <%= f.button :submit %>

0
source

Not sure how and where you install @school. if @school is zero, the above answer may not work.

However, you can also use

 <%= simple_form_for [:school, @student] do |f| %> <%= f.input :first_name %> <%= f.input :last_name %> <%= f.submit %> <% end %> 
0
source

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


All Articles