インターコムを使用してユーザーにメールを送信するレーキ タスクがあります。私が抱えている問題は、link_to メソッドが存在しないことです。
上部に url_helpers を含めました (適切な場所かどうかはわかりません)。私が得ているエラーは次のとおりです: NoMethodError: undefined method
link_to' for main:Object`
これが可能かどうか、また何か間違ったことをしている場合はお知らせください。
レーキタスクは次のとおりです。
include Rails.application.routes.url_helpers
namespace :example do
desc "TODO"
task affiliate_bonus: :environment do
User.all.each do |user|
if user.invited && user.invited.size > 0
user_affiliate_bonus = AffiliateBonu.where(inviter_id: user.id)
@the_user_af_bonus = 0
@total_affiliate_bonus = 0
user_affiliate_bonus.each do |ab|
@total_affiliate_bonus = @total_affiliate_bonus.to_f + ab.btc_bonus_amount
if ab.fulfilled == false
@the_user_af_bonus = @the_user_af_bonus.to_f + ab.btc_bonus_amount
if user.btc_wallet_address
ab.fulfilled = true
ab.save!
end
end
end
if @the_user_af_bonus >= 0 && user.affiliate_subscription
@intercom = Intercom::Client.new(app_id: ENV["INTERCOM_APP_ID"], api_key: ENV["INTERCOM_APP_KEY"])
user_receive = @intercom.users.create(email: user.email, user_id: user.id, :signed_up_at => Time.now.to_i)
referral_link_text = link_to("https://www.example.com/ref/#{user.referral_link}", "https://www.example.com/ref/#{user.referral_link}")
unsubscribe_text = link_to("click here", {:controller => "users", :action => "affiliate_unsubscribe", :user_id => user.id })
balance_text = link_to('Balance', "https://example.com/users/balance")
text =
"
<% if user.first_name %>
<p>Dear <%= user.first_name %>,</p>
<% else %>
<p>Dear Customer,</p>
<% end %>
<p>
Your referral link: #{referral_link_text} has generated $ <%= @bonus %> for you this week.
<% if @bonus > 0 %>
This amount was sent to your #{balance_text}.
<% end %>
</p>
<p>Regards,</p>
<p>George @<strong>Kaboom</strong></p>
<p>--<br>
PS. You are receiving this email update because your link has been used to sign up.</p>
<p>To unsubscribe from your profit reports, #{unsubscribe_text}.</p>
"
@intercom.messages.create({ :message_type => 'email', subject: "Your Weekly Referral Earnings Report", :body => text, :template => "plain", :from => { :type => 'admin', :id => "55070" }, :to => { type: "user", :id => user_receive.id } })
end
end
end
end
end