我有一个非常恼人的错误,它并没有告诉我应该在哪里解决这个问题。
undefined method `' for #<Conference:0x00000112a617c0>当我想通过Rails管理保存一个新的会议记录时,会发生错误
守则如下:
会议类:
class Conference < ActiveRecord::Base
include TheDate
end模块TheDate:
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
endMeetingDate类:
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你知道是什么引起的吗?由于错误中没有方法名,我不知道该在哪里查找.
谢谢
发布于 2014-07-10 15:12:36
应该使用.where方法,如下所示:
# change this
where(:'event_dates.dateable_type' => 'Conference')
# to the following syntax:
where(event_dates: { dateable_type: 'Conference' })发布于 2014-08-04 20:39:38
我也有同样的问题。这篇文章似乎有一个修正,虽然我觉得它有点不可取。在最近的一个补丁中,Rails加载的方式发生了变化,它扰乱了包含的块中的GeneratedAssociationMethods。
https://stackoverflow.com/questions/24679917
复制相似问题