0

我有一个嵌套模型

resources :customers do 
 resources :readings
end

我现在想从客户的显示视图中访问我的 ../customerid/readings/new 视图。

在客户显示视图中,如何使用按钮调用新读数视图?

客户展示.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>
4

2 回答 2

2

我及时解决了

  <%= link_to 'Readings', customer_readings_path(@customer) %> |
于 2012-11-28T21:20:22.950 回答
1

根据Ruby on Rails 路由指南的“2.7 嵌套资源”章节/customers/:customer_id/readings/new,要获取以下 URL ,请使用:

customer_readings_path(@customer) # Generate the path for new Reading which belongs to @customer
于 2012-11-28T21:21:05.473 回答