访问"joins"操作结果时"RuntimeError unknown class:"



访问Model.joins(ActiveRecord::Relation)操作结果出错

模型如下:

class Device < ActiveRecord::Base
    has_one :android_device
    def Device.find_devices_by_attributes(device_params)
        android_devices = AndroidDevice.find_android_devices_by_attributes(device_params[:android_device_attributes])
        if (!android_devices.nil?) && (!android_devices.empty?)
            devices_android_device = Device.joins(android_devices)   <--- this is the line the error occures on.
        end
    end
end
class AndroidDevice < ActiveRecord::Base
    belongs_to :device
    def AndroidDevice.find_android_devices_by_attributes (android_params)
        android_devices = AndroidDevice.where("android_id = ?", android_params[:android_id])
    end
end
日志显示:

2014-05-21T08:46:14.719594+00:00 app[web.1]: Completed 500 Internal Server Error in 87ms
2014-05-21T08:46:14.721376+00:00 app[web.1]: RuntimeError (unknown class: AndroidDevice):

DeviceAndroidDevice都是通过命令rails g scaffold ...

创建的

我不明白为什么AndroidDevice是一个未知类

您不能使用.joins与ActiveRecord::Relation作为参数

可能需要http://apidock.com/rails/ActiveRecord/SpawnMethods/merge功能

最新更新