2012-12-02 4 views
1

는 그래서 난이 오류가있어 :중복 오류가있는 경로가 레일스에서 ​​일치하지 않습니다. 디버깅하는 방법?

Routing Error 

No route matches {:action=>"show", :controller=>"products", :list_id=>#<Product id: 1, name: "a", model: "", description: "", version: "", company: "", price: nil, image_source: nil, created_at: "2012-12-02 18:43:26", updated_at: "2012-12-02 18:43:26">} 

주의 사항 : list_id로 => # ...이 작은 엉망 보인다. 아무 래도 Product이 들어 있습니다. 여기

여기

class Product < ActiveRecord::Base 
    attr_accessible :company, :description, :model, :name, :price, :version 

    has_many :list_product_interactions 
    has_many :lists, :through => :list_product_interactions 

    validates_uniqueness_of :name, :scope => [:version] 

여기
class List < ActiveRecord::Base 
    attr_accessible :activity, :description, :title 

    has_many :list_product_interactions 
    has_many :products, :through => :list_product_interactions, :order => "list_product_interactions.votes_up DESC" 

이 오류가

class ListProductInteraction < ActiveRecord::Base 
    attr_accessible :list_id, :product_id, :votes_activity, :votes_down, :votes_total, :votes_up 

    belongs_to :list 
    belongs_to :product 

list_product_interactions.rb 나는의 중복을 만들 때 발생하는 것입니다 list.rb입니다 product.rb입니다 제품 (이미 사용 된 이름의 제품).

class ProductsController < ApplicationController 
    def create 
    @list = List.find(params[:list_id]) 
    @product = @list.products.build(params[:product]) 
    if @list.save 
     raise "ok" 
     redirect_to list_path(@list) 
    else 
     @list.reload 
     params[:list_id] = @list.id 
     render template: "lists/show" 
    end 
    end 

    def show 
    @product = Product.find(params[:id]) 
    end 
end 

가 어떻게 디버깅 할

products_controller.rb : 여기에 오류가 발생 컨트롤러는 무엇입니까? 감사합니다

업데이트 :

class ListsController < ApplicationController 
    def index 
    @lists = List.all 
    end 

    def new 
    @list = List.new 
    end 

    def create 
    @list = List.new(params[:list]) 
    if @list.save 
     redirect_to @list 
    else 
     render :new 
    end 
    end 

    def show 
    @list = List.find(params[:id]) 
    @product = @list.products.build 
    nil 
    end 
end 

목록 lists_controller.rb 템플릿

h1 
    = @list.title 
br 
= @list.description 
hr 
- @list.products.each do |product| 
    - if !product.id.nil? 
    = link_to product.name, list_product_path(product), class: "product_link" 
    ' 
    = product.version 
    ' 
    = link_to "up:", "/lists/#{@list.id}/products/#{product.id}/vote_up", :method => :put 
    = product.product_up_votes(@list.id) 
    ' 
    = link_to "down:", "/lists/#{@list.id}/products/#{product.id}/vote_down", :method => :put 
    = product.product_down_votes(@list.id) 

hr 
h3 Add products: 
= form_for([@list, @product]) do |f| 
    - if @product.errors.any? 
    |product errors 
    = pluralize(@product.errors.count, "error") 
    ul 
    - @product.errors.full_messages.each do |msg| 
     li 
     = msg 
    br 
    = f.label :name 
    = f.text_field :name 
    br 
    = f.label :version 
    = f.text_field :version 
    br 
    = f.submit 
hr 
= link_to "All lists", lists_path 
+0

"lists/show"템플릿을 제공 할 수 있습니까 – krichard

+0

lists 컨트롤러와 show 템플릿이 추가되었습니다. – AdamT

답변

0

루비 - 디버그 디버깅 레일


레일에 사용되는 디버거, 루비를 보여 추가 -debug, 보석으로 제공됩니다. 를 설치하려면, 단지 실행 인터프리터가 멈추는 debugger 문에 도달하고 interactivly 콘솔에서 현재 환경을 탐색 할 때

sudo gem install ruby-debug 
# if you run 1.9 
sudo gem install debugger 

는 그런 다음

<% debugger;true %> 
# or in the controller/model/lib 
def somemethode 
    # ... 
    debugger 
    # ... 
end 

처럼 뭔가를 할 수 있습니다.

문제


...아마 여기에 있습니다 :

= link_to product.name, list_product_path(product), class: "product_link" 

그게 전부를 list_product_path 가장 가능성이 너무 list_product_path(@list,product) 같은 목록 개체와 해당 제품을 필요로하거나 lists_products_path(product)

0

당신의 :list_id PARAM이 도청되는 값을 의미 할 수 있기 때문에 :

Routing Error 
No route matches {:action=>"show", :controller=>"products", 
    :list_id=>#<Product id: 1, name: "a", model: "", description: "", version: "", company: "", price: nil, image_source: nil, created_at: "2012-12-02 18:43:26", updated_at: "2012-12-02 18:43:26">} 

이것은 라우팅 오류이므로 을 게시해야합니다. 0이고 출력은 rake routes 일 수 있습니다. 당신이

를 사용해야하므로,

#/config/routes.rb 
resources :lists do 
    resources :products 
end 

그게 사실 다음 krichard이 맞을 경우 :

내가 무엇을 말할 수에서

, 당신은 중첩 된 리소스 경로, 이런 식으로 뭔가에 의존하는 것 같다 거치지 않고

list_product_path(:id => product.id, :list_id => @list.id) list_product_path(product,@list) #this should also work 
모두 product.idlist.id, 귀하의 요청은 중첩 된 리소스 경로를 일치하지 않습니다.

관련 문제