我想從我的/clients/:client_id
show
頁面鏈接到現有路由/clients/:client_id/invoices/:id
並不能工作如何做到以正確的路由。無法鏈接使用的link_to
我有一個has_many through:
關係,這裏是我models
class Client < ActiveRecord::Base
has_many :invoices
has_many :items, through: :invoices
class Invoice < ActiveRecord::Base
belongs_to :user
belongs_to :client
has_many :items, :dependent => :destroy
accepts_nested_attributes_for :items, :reject_if => :all_blank, :allow_destroy => true
class Item < ActiveRecord::Base
belongs_to :invoice
belongs_to :client
我的路線
resources :clients do
resources :invoices
end
resources :invoices
我的客戶端控制器顯示行動
def show
@client = Client.find(params[:id])
@invoices = @client.invoices.build
end
而且我的客戶show.html.erb
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>Sender</th>
<th>Reciever</th>
<th>Amount</th>
<th>Currency</th>
<th>Date</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @client.invoices.each do |invoice| %>
<tr>
<td><%= invoice.sender %></td>
<td><%= invoice.reciever %></td>
<td><%= invoice.amount %></td>
<td><%= invoice.currency %></td>
<td><%= invoice.date %></td>
<td><%= link_to 'Show', invoices_path(@clients, @invoice) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
每次我點擊link_to show
其路由我/invoices
我已經嘗試了一堆不同link_to
格式,但我一直沒能弄明白。