I'm using SimpleForm 开发者_StackOverflow中文版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 %>
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 %>
Just use <%= f.submit %>
instead of <%= f.button :submit %>
Not sure how or where, you are setting the @school. if @school is nil 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 %>
精彩评论