[27] pry(main)> c = Channel.find 6 => #<Channel id: 6, title: "会员", cid: "96", pid: "", channel_position: "", data_type: "", filter_id: "", version: "1.2.0"> [28] pry(main)> c.valid? => true [29] pry(main)> [30] pry(main)> [31] pry(main)> c.has_filter => "1" [32] pry(main)> c.cid => "96" [33] pry(main)> c.is_default_channel => "1" [34] pry(main)> c.reload => #<Channel id: 6, title: "会员", cid: "96", pid: "", channel_position: "", data_type: "", filter_id: "", version: "1.2.0"> [35] pry(main)> c.previous_changes => {} [36] pry(main)> c.title = c.title + 1 TypeError: no implicit conversion of Fixnum into String from (pry):43:in `+' [37] pry(main)> c.title = c.title + '1' => "会员1" [38] pry(main)> c.save => true [39] pry(main)> c.previous_changes => {"title"=>["会员", "会员1"], "updated_at"=>[Fri, 08 Apr 2016 08:10:30 CST +08:00, 2016-04-08 12:28:20 +0800]} [40] pry(main)> a, b = [1,2] => [1, 2] [41] pry(main)> a => 1 [42] pry(main)> b => 2
model里的private方法
def update_auto_activate_job if active? # 对已经设置了自动开启时间的视频进行手动开启操作 if (change = previous_changes[:state]) && change[0] == 0 if job = Sidekiq::ScheduledSet.new.find_job(auto_activate_job_id) job.delete end update_attributes auto_activated_at: nil, auto_activate_job_id: nil end else # 针对未开启的视频,设置,取消或者更新定时开启时间 if change = previous_changes[:auto_activated_at] original_value, new_value = change if original_value.nil? # 设置定时开启,id是当前model里的id job_id = AutoActivateWorker.perform_at new_value, id update_attribute :auto_activate_job_id, job_id elsif new_value.nil? # 取消定时开启 if job = Sidekiq::ScheduledSet.new.find_job(auto_activate_job_id) job.delete end update_attribute :auto_activate_job_id, nil else # 更新定时开启时间 if job = Sidekiq::ScheduledSet.new.find_job(auto_activate_job_id) job.reschedule new_value end end end end end