는 그래서 난이 오류가있어 :중복 오류가있는 경로가 레일스에서 일치하지 않습니다. 디버깅하는 방법?
이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
"lists/show"템플릿을 제공 할 수 있습니까 – krichard
lists 컨트롤러와 show 템플릿이 추가되었습니다. – AdamT