gpt4 book ai didi

ruby-on-rails-3 - 简单形式的关联给出 "undefined method ` klass' for nil :NilClass"error

转载 作者:行者123 更新时间:2023-12-04 07:18:14 25 4
gpt4 key购买 nike

在我的 Rails 3 应用程序中,我有以下简单的关系结构:

class Rollout < ActiveRecord::Base
has_many :items, :through => :rollout_items
end

class RolloutItem < ActiveRecord::Base
belongs_to :rollout
belongs_to :item
end

class Item < ActiveRecord::Base
has_many :rollouts, :through => :rollout_items
end

Controller :
def new
@rollout = Rollout.new
end

我收到以下形式的上述错误:
<%= simple_form_for @rollout do |f| %>
<%= f.association :items %>
<% end %>

最佳答案

Rollout之间存在缺失关系和 RolloutItem :

class Rollout < ActiveRecord::Base
has_many :rollout_items # This.
has_many :items, :through => :rollout_items
end
Item 也是如此.

关于ruby-on-rails-3 - 简单形式的关联给出 "undefined method ` klass' for nil :NilClass"error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16651479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com