开发者

Deeply nested routes in Rails 3

I've got this in my show.html.erb:

<%= link_to "Pay on this contract", new_product_contract_payment_path %>

And this in routes.rb

  resources :products do
    resources :contracts do
      resources :payments 
   开发者_运维技巧 end
  end 

But when I view the contract page, I get this error:

No route matches {:action=>"new", :controller=>"payments"}

The route shows up when I use rake routes and the payments controller is there. This is my new method in the payments controller.

 def new
    @contract = Contract.find(params[:contract])
    @payment = @contract.line_items.build

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @payment }
    end
  end

Any thoughts on what's throwing the error?


You need to pass in a contract and a product, so something like:

 new_product_contract_payment_path(@product, @contract) 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜