Railsの初心者は、次の3つのモデルと関係を持つサンプルアプリを作成します。
営業担当者:
class Salesperson < ActiveRecord::Base
has_many :clients
クライアント:
class Client < ActiveRecord::Base
has_many :orders
belongs_to: salesperson
注文:
class Order < ActiveRecord::Base
belongs_to :client
clients / show.html.erbページに、次のようにレンダリングするパーシャルがあります。
<table>
<tr>
<th>Name</th>
<th>Total Orders</th>
<th>Email</th>
<th></th>
</tr>
<% @salesperson.clients.each do |client| %>
<tr>
<td><%= client.full_name %></td>
<td><%= client.orders.count %></td>
<td><%= client.email %></td>
<td><%= link_to 'View Client', client_path %></td>
</tr>
<% end %>
</table>
リソースはすべてネストされており、ページは次の1つを除いて機能しているようです。
すべてが動的ですが、クライアントパス:クライアント名、注文、電子メールはすべて営業担当者に表示されますが、クライアントリンクの表示は常にclients /:idリンクを指しているようです。ここで:idは営業担当者IDですが、クライアントIDではありません。
たとえば、営業担当者:idが1であるため、すべてのクライアントパスはテーブル全体のclients/1を指します。
表の他の部分と同様に、クライアントリンクルートを正しく動的にするにはどうすればよいですか?