2012-11-28 48 views
0

我有一個嵌套的模型嵌套調用模型視圖

resources :customers do 
resources :readings 
end 

我想現在從客戶的放映視圖訪問我../customerid/readings/new視圖。

如何在客戶顯示視圖中使用按鈕調用新的閱讀視圖?

客戶show.html

<%- model_class = Customer -%> 
<div class="page-header"> 
<h1><%=t '.title', :default => model_class.model_name.human %></h1> 
</div> 

<dl class="dl-horizontal"> 
<dt><strong><%= model_class.human_attribute_name(:name) %>:</strong></dt> 
<dd><%= @customer.name %></dd> 
<dt><strong><%= model_class.human_attribute_name(:customer_currency) %>:</strong></dt> 
<dd><%= @customer.customer_currency %></dd> 
<dt><strong><%= model_class.human_attribute_name(:payment_terms) %>:</strong></dt> 
<dd><%= @customer.payment_terms %></dd> 
<dt><strong><%= model_class.human_attribute_name(:phase_type) %>:</strong></dt> 
<dd><%= @customer.phase_type %></dd> 
<dt><strong><%= model_class.human_attribute_name(:billing_address) %>:</strong></dt> 
<dd><%= @customer.billing_address %></dd> 
<dt><strong><%= model_class.human_attribute_name(:first_name) %>:</strong></dt> 
<dd><%= @customer.first_name %></dd> 
<dt><strong><%= model_class.human_attribute_name(:last_name) %>:</strong></dt> 
<dd><%= @customer.last_name %></dd> 
<dt><strong><%= model_class.human_attribute_name(:mobile) %>:</strong></dt> 
<dd><%= @customer.mobile %></dd> 
<dt><strong><%= model_class.human_attribute_name(:email) %>:</strong></dt> 
<dd><%= @customer.email %></dd> 
</dl> 


<div class="form-actions"> 
<%= link_to t('.back', :default => t("helpers.links.back")), 
      customers_path, :class => 'btn' %> 
<%= link_to t('.edit', :default => t("helpers.links.edit")), 
      edit_customer_path(@customer), :class => 'btn' %> 


<%= link_to t('.destroy', :default => t("helpers.links.destroy")), 
      customer_path(@customer), 
      :method => 'delete', 
      :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, 
      :class => 'btn btn-danger' %> 
</div> 

回答

1

據紅寶石上Rails的路由指南"2.7 Nested Resources" Chapter,得到以下網址/customers/:customer_id/readings/new,使用此:

customer_readings_path(@customer) # Generate the path for new Reading which belongs to @customer 
+0

謝謝你的指導 – zurik

2

我解決它在時間

<%= link_to 'Readings', customer_readings_path(@customer) %> |