次のコードセクションがあります。
<%= link_to 'Edit', edit_computer_path(@computer) %> |
<%= link_to 'Back', computers_path %>
<div>
<h2>New config</h2>
<%= render "kernel_configs/computerkernelconfig", :locals => { :computer => @computer } %>
</div>
<div>
<h2>Submitted Configs</h2>
<table>
<tr>
<th>Rating</th>
<th>Title</th>
<th>Contributor</th>
<th>Features</th>
<th>Config file</th>
<th></th>
</tr>
<%= render @computer.kernel_configs %>
</table>
</div>
ルートがないと不平を言う:
ActionController::RoutingError (ルートが一致しません {:action=>"edit", :controller=>"kernel_configs", :id=>#}):
app/views/kernel_configs/_kernel_config.html.erb:13:in_app_views_kernel_configs__kernel_config_html_erb___3252059691242213705_26424640' app/views/computers/show.html.erb:34:in
_app_views_computers_show_html_erb___4341746115390966607_23819760'
app/controllers/computers_controller.rb:18:in `show'
最初のレンダリングを 2 番目のレンダリングの後に移動すると、ページはエラーなしで正常にレンダリングされます。したがって、ルートがあると確信しています。実際には、おそらく次のいずれかです。
edit_kernel_config GET /kernel_configs/:id/edit(.:format) kernel_configs#edit
edit_computer_kernel_config GET /computers/:computer_id/kernel_configs/:id/edit(.:format) kernel_configs#edit
参考までに、パーシャルは次のとおりです。
<%= form_for( [@computer,@computer.kernel_configs.build], :multipart => true ) do |form| %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<div class="field">
<%= form.label :contributed_by %>
<%= form.text_field :contributed_by %>
</div>
<div class="field">
<%= form.label :features %><br />
<%= form.text_area :features %>
</div>
<div class="field">
<%= form.label "Upload File" %><br />
<%= form.file_field :kernelconfig %>
</div>
<div class="field">
<%= form.submit %>
</div>
<% end %>
_kernel_congif パーシャル:
<tr>
<td><%= kernel_config.rating %></td>
<td><%= kernel_config.title %></td>
<td><%= kernel_config.contributed_by %></td>
<td><%= kernel_config.features %></td>
<td><%= truncate kernel_config.kernelconfig %></td>
<td><%= link_to 'Edit', edit_kernel_config_path(kernel_config) %></td>
</tr>