0

我有一个嵌套模型

resources: customers do
  resources: readings
end

我正在尝试创建一个新的客户阅读。我在读数控制器中的新动作是

#GET /customers/:customer_id/readings/new
def new
#1st you retrieve the customer
 customer = Customer.find(params[:customer_id])
#2nd you build a new one
 @reading = customer.readings.build
  respond_to do |format|
   format.html #new.html.erb  
  end
end

我在读数文件夹中创建新读数的视图是

<div class = "page-header">
   <h1> New Readings </h1>
</div>

<%= render 'form_reading' %>

我的 _form_reading 是

<%= simple_form_for [@reading.customer, @reading], :html => { :class => 'form-horizontal'    } do |f| %>
<%= render "shared/error_messages", :target => @reading %>
<%= f.input :customer_id %>
<%= f.input :date_of_reading, :as => :date %>
<%= render_readings_conditionally(f) %>
<div class="form-actions">
  <%= f.button :submit, :class => 'btn-primary' %>
  <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
              customer_reading_path, :class => 'btn' %> 
</div>
<% end %>

但是,我很困扰,对 /customers/1/readings/new 的调用返回

没有路线匹配 {:action=>"show", :controller=>"readings"}

我错过了什么?

4

2 回答 2

0

在你打电话给customer_reading_path你时,你没有传递 customer_id。你可以这样做

customer_readings_path(@reading.customer)

请注意它的读数而不是读数

于 2012-11-23T05:59:49.693 回答
0

客户阅读路径(:customer_id => <Pass customer ID here>)

于 2012-11-23T05:54:09.930 回答