路由:
resources :products, :shallow => true do
resources :articles
end
表单:
<%= form_for @article, url: new_product_article_path(@article) do |f| %>
<p>
<%= f.label "title" %></br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label "content" %></br>
<%= f.text_area :content %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
log:
tarted GET "/products/1/articles/new" for 127.0.0.1 at 2015-02-04 21:12:28 +0800
Processing by ArticlesController#new as HTML
Parameters: {"product_id"=>"1"}
Rendered articles/new.html.erb within layouts/application (2.2ms)
Completed 500 Internal Server Error in 7ms
ActionView::Template::Error (No route matches {:action=>"new", :controller=>"articles", :product_id=>nil} missing required keys: [:product_id]):
1: <h1>New article</h1>
2:
3: <%= form_for @article, url: new_product_article_path(@article) do |f| %>
4:
5: <p>
6: <%= f.label "title" %></br>
app/views/articles/new.html.erb:3:in `_app_views_articles_new_html_erb___2302585143041901570_70250353575640'
(No route matches {:action=>"new", :controller=>"articles", :product_id=>nil} missing required keys: [:product_id]): product_id =》nil,这个参数是怎么通过 form_for 传递的?