首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于#<Conference:0x00000112a617c0>的未定义方法‘’

用于#<Conference:0x00000112a617c0>的未定义方法‘’
EN

Stack Overflow用户
提问于 2014-07-10 15:00:04
回答 2查看 81关注 0票数 2

我有一个非常恼人的错误,它并没有告诉我应该在哪里解决这个问题。

代码语言:javascript
复制
undefined method `' for #<Conference:0x00000112a617c0>

当我想通过Rails管理保存一个新的会议记录时,会发生错误

守则如下:

会议类:

代码语言:javascript
复制
class Conference < ActiveRecord::Base

  include TheDate

end

模块TheDate:

代码语言:javascript
复制
module TheDate
  extend ActiveSupport::Concern

   included do
     has_many :meeting_dates, as: :dateable, dependent: :destroy
     accepts_nested_attributes_for :meeting_dates, :allow_destroy => true
   end
end

MeetingDate类:

代码语言:javascript
复制
class MeetingDate < ActiveRecord::Base

  belongs_to :dateable, polymorphic: true
  belongs_to :conference, -> { where(:'event_dates.dateable_type' => 'Conference') }, foreign_key:   :dateable_id
  belongs_to :course, -> { where(:'event_dates.dateable_type' => 'Course') }, foreign_key: :dateable_id
  belongs_to :meeting, -> { where(:'event_dates.dateable_type' => 'Meeting') }, foreign_key: :dateable_id

end

你知道是什么引起的吗?由于错误中没有方法名,我不知道该在哪里查找.

谢谢

EN

回答 2

Stack Overflow用户

发布于 2014-07-10 15:12:36

应该使用.where方法,如下所示:

代码语言:javascript
复制
# change this
where(:'event_dates.dateable_type' => 'Conference')

# to the following syntax:
where(event_dates: { dateable_type: 'Conference' })
票数 1
EN

Stack Overflow用户

发布于 2014-08-04 20:39:38

我也有同样的问题。这篇文章似乎有一个修正,虽然我觉得它有点不可取。在最近的一个补丁中,Rails加载的方式发生了变化,它扰乱了包含的块中的GeneratedAssociationMethods。

https://github.com/rails/rails/issues/15253

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24679917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档