我已在SO搜索對象不支持檢查錯誤是什麼導致對象(模型)不支持檢查?
和一些鏈接包括this one here和this one too。還有更多,並在github上,但他們都沒有解決原因。
我有我的模型這裏
class Tool < ActiveRecord::Base
include PublicActivity::Common
after_initialize :defaults
after_save :explicit_updates
belongs_to :job
belongs_to :kind
has_one :location, :through => :job
has_one :rig, :through => :job
belongs_to :vendor
has_paper_trail
scope :deployable_by_type, ->(kind_id) { where(status: "deployable",
kind_id: kind_id)}
scope :deployable, -> { where(status: "deployable")}
scope :deployed, -> { where(status: "deployed")}
scope :in_transit, -> { where(status: "in_transit")}
scope :under_maintenace, -> { where(maintenance_status: true)}
scope :failed, -> { where(failed: true)}
scope :requiring_service, -> { where(service_required: true,
maintenance_status: false)}
validates :kind_id, presence: true
validates :serial_number, presence: true
validates :department, presence: true
validates :size, presence: true, numericality: {
:greater_than => 0}
validates :description, presence: true
validates :hours, presence: true,
numericality: {
:greater_than_or_equal_to => 0 }
validates :length, presence: true, numericality: {
:greater_than => 0 }
validates :vendor_id, presence: true
validates :cost, presence: true
validates :service_hours, presence:true, numericality: {
:greater_than => 0}
validates :sensor_type, presence: true
def defaults
self.status ||= "deployable"
self.hours ||= 0
self.failed ||= false
self.service_required ||= false
self.maintenance_status ||= false
self.daily_job_monitor ||=false
end
def explicit_updates
if !self.failed
self.update_columns(failure_comment: nil)
end
end
end
,當我運行與選擇上有一個命令,我得到一個錯誤
irb(main):002:0> Tool.select(:kind_id)
Tool Load (0.8ms) SELECT kind_id FROM "tools"
(Object doesn't support #inspect)
是否有導致此特定設置?
你正在使用哪個版本的Rails?我沒有看到任何問題 –
我正在使用rails 4.0.2 –
您是否在Tool類中定義了'initialize'方法? – Drenmi