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/newreturnsへの電話

{:action => "show"、:controller=>"readings"}に一致するルートはありません

私は何が欠けていますか?

4

2 に答える 2

0

customer_reading_path(:customer_id => <Pass customer ID here>)

于 2012-11-23T05:54:09.930 に答える
0

あなたがあなたに電話するcustomer_reading_pathとき、customer_idを渡していない。あなたはそれをすることができます

customer_readings_path(@reading.customer)

読み取り値であり、読み取り値ではないことに注意してください。

于 2012-11-23T05:59:49.693 に答える