I’m trying to call two lengthy commands in a when statement, but for some reason, because of its syntax, it performs two of the commands twice when it is called :
@email = Email.find(params[:id])
delivery = case @email.mail_type
# when "magic_email" these two delayed_jobs perform 2x instead of 1x. Why is that?
when "magic_email" then Delayed::Job.enqueue MagicEmail.new(@email.subject, @email.body)
Delayed::Job.enqueue ReferredEmail.new(@email.subject, @email.body)
when "org_magic_email" then Delayed::Job.enqueue OrgMagicEmail.new(@email.subject, @email.body)
when "all_orgs" then Delayed::Job.enqueue OrgBlast.new(@email.subject, @email.body)
when "all_card_holders" then Delayed::Job.enqueue MassEmail.new(@email.subject, @email.body)
end
return delivery
How can I make it so that when I hit when "magic_email", it only renders both those delayed jobs once ?
I have tried this with following example:
q = [] a = case 1 when 1 then q.push 'ashish' q.push 'kumar' when 2 then q.push 'test' when 4 then q.push 'another test' end puts a.inspect #######["ashish", "kumar"]This is working fine. It means your case-when syntax is ok. It might be you have aome other problem.