Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using SimpleForm in Rails 3. How do I make the submit button for this nested 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 %>
like image 244
Nerian Avatar asked Dec 06 '22 00:12

Nerian


1 Answers

The right code for the view is:

<%= simple_form_for [@school, @student] do |f| %>
     <%= f.input :first_name %>
     <%= f.input :last_name %>
     <%= f.button :submit  %>
<% end %>
like image 199
Nerian Avatar answered Dec 16 '22 05:12

Nerian