cronのロジック部分を書いたのですがエラーで動きません
require "#{Rails.root}/app/models/item"を追加してもエラーで動きませんでした。
どうしたら良いでしょうか、ご教授ください
require "#{Rails.root}/app/models/item"がない場合のエラー
<class:Item>': undefined local variable or method
item' for Item:Class (NameError)
from /Users/xxx/Documents/xxxxxxx3.0.0/lib/tasks/item.rb:1:in `<top (required)>'
require "#{Rails.root}/app/models/item"追加時のエラー
`<top (required)>': superclass mismatch for class Item (TypeError)
lang
1#エラーになる 2# /lib/tasks/item.rb 3 4require "#{Rails.root}/app/models/item" 5 6class Item 7 def self.formation_check 8 @formation_item = Item.where("limit_day >= ?", Time.now, xxx: true) 9 @formation_item.all_update({formation: true}) 10 end 11end 12 13$ rails runner Item.hoge
lang
1#うまく動く 2# /lib/tasks/test.rb 3class Test 4 def self.hoge 5 puts "hoge" 6 end 7end 8 9 10# /config/application.rb 11module xxx # railsアプリ名 12 class Application < Rails::Application 13 config.autoload_paths += %W(#{config.root}/lib) 14 config.autoload_paths += Dir["#{config.root}/lib/**/"] 15 end 16end 17 18$ rails runner Test.hoge
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。