0

次のコードセクションがあります。

<%= 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>
4

1 に答える 1

0

何が起こっているかというと、リストの前にフォームがあるため@computer.kernel_configs.build、新しい空のレコードを に追加する呼び出しを行っているということ@computer.kernel_configsです。

この新しい空のレコードを表示しようとしているため、パーシャルがクラッシュしている可能性があります。

これが、フォーム パーシャルをコレクション パーシャルの下に移動すると、正常に機能する理由です。

編集:

予想どおり、空のオブジェクトへのリンクを作成しようとしています。

エラーは次の行で発生しています。

# _kernel_config.html.erb
<td><%= link_to 'Edit', edit_kernel_config_path(kernel_config) %></td>

edit_kernel_config_path空の へのパスを見つけることができませんkernel_config

于 2013-04-22T03:30:39.913 に答える