実現したいこと
クラウドファンディングのようなサイトをrailsで開発・運営しております。
Event(企画) を応援したContributor(寄付者)の寄付金額の手数料のカラムを、
コマンド入力で一気にアップデートしたいです。
しかし、Contributorに紐づいているEventが削除されているとエラーが発生してしまいます。
(Eventが削除されていても、Contributorは削除されておりませんため)
Eventが削除されていても、同じアップデートを継続させたいのですが、
どのようにコーディングすればよいのでしょうか?
大変お忙しい中恐縮ですが、教えて頂けますと大変嬉しいです。
開発の前提
クラウドファンディングのようなサイトをrailsで開発・運営しております。
発生している問題・エラーメッセージ
ruby
1undefined method `created_at' for nil:NilClass
該当のソースコード
models/concerns/Fee_update.rb
ruby
1module Fee_update 2 class Fee_up 3 def self.fees 4 Contributor.preload(:event).find_each do |contributor| 5 if contributor.event.created_at < Date.new(2021,8,1) 6 fee_stripe = contributor.contribution_amount * 0.036 7 fee_we = contributor.contribution_amount * 0.214 8 fee_user = contributor.contribution_amount * 0.75 9 else 10 fee_stripe = contributor.contribution_amount * 0.036 11 fee_we = contributor.contribution_amount * 0.264 12 fee_user = contributor.contribution_amount * 0.7 13 end 14 contributor.update!(fee_stripe:fee_stripe, fee_we:fee_we, fee_user:fee_user) 15 end 16 end 17 end 18end 19
実行コマンド
ruby
1heroku run rails runner Fee_update::Fee_up.fees
カラム
Contributor
ruby
1event_id #こちらによって、Eventと紐づいています 2fee_stripe 3fee_we 4fee_user
試したこと
https://style.potepan.com/articles/30566.html#Ruby-2
こちら等、色々見まして、
begin
resque
end
を使用すればよいことは分かってきたのですが、
if内でどう処理をすれば、コマンドの実行が継続されるのかが分からず、途方に暮れております。
大変お忙しい中申し訳ありませんが、教えて頂けますと本当に助かります。
どうぞよろしくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー