Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法`产品投标路径';_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

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
不是零。