我有以下代码部分:
<%= 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'
如果我在第二个之后移动第一个渲染,则页面渲染良好而没有错误。所以我很确定有一条路线,实际上可能是其中之一:
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>