Ruby on rails 未定义的方法`产品投标路径';
我明白了,, 当我想展示我的产品时,我遇到以下错误:Ruby on rails 未定义的方法`产品投标路径';,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我明白了,, 当我想展示我的产品时,我遇到以下错误: undefined method `product_bids_path' 在我的路由文件中: devise_for :users resources :products do resources :auctions, only: [:create] do resources :bids, only: [:create] end end 在products/show.html.erb =render
undefined method `product_bids_path'
在我的路由文件中:
devise_for :users
resources :products do
resources :auctions, only: [:create] do
resources :bids, only: [:create]
end
end
在products/show.html.erb
=render "auction"
=render "bid"
这是我的部分出价:
= form_for [ @product, @product.auction, Bid.new] do |f|
在本表单中,帮助者需要发送产品拍卖出价路径url请求,但其发送产品出价路径url请求
我应该如何为向产品拍卖出价路径发送请求的帮助者编写正确的表单似乎是注释解决了这个问题
为了方便读者,如果您有一组嵌套的路由(如下所示),则必须确保使用所有依赖对象调用路径:
resources :products do
resources :auctions, only: [:create] do
resources :bids, only: [:create]
end
end
products_auctions_bids_path(@product, @auction, @bid)
现在
关于这一点,有一点很重要——即不应嵌套超过一个级别的路由:
资源嵌套深度不得超过1级
您确实需要确保能够基于比所有三个嵌套资源的主键
更少的唯一信息来调用路由
我知道您没有调用单独的路径(仅create
),但是像您这样嵌套它仍然是一种不好的模式
有几种补救方法;我个人只会使用拍卖
和出价
:
#config/routes.rb
resources :auctions, only: :create do
resources :bids
end
拍卖
无论如何都应该基于主键是唯一的
#app/models/auction.rb
class Auction < ActiveRecord::Base
belongs_to :auction
has_many :bids
end
#app/models/bid.rb
class Bid < ActiveRecord::Base
belongs_to :auction
end
#app/models/auction.rb
类拍卖
这将允许您明确识别拍卖,然后根据需要创建出价。产品和拍卖之间的关系是什么?产品有一个:拍卖看起来像@product。拍卖
为零。试着调试它。是的。首先,我们显示产品,然后用户创建拍卖只需确保@product.auction
不是零。