2012-11-23 35 views
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”,:con troller =>“readings”}

我在想什么?

回答

0

在你打电话给你不及格CUSTOMER_ID customer_reading_path。你可以做到这一点作为

customer_readings_path(@reading.customer) 

请注意,其读数,而不是阅读

0

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

+0

谢谢,它已经工作。其实我编辑它到customer_readings_path – zurik