Note that there are some explanatory texts on larger screens.

plurals
  1. POHow add delay before sending an Email?
    primarykey
    data
    text
    <p>I am referring Agile web developments with Rails 4th edition book. I have created two Email notification first for confirmation of order, second for shipped order. Now I want to add a delay of 5 minutes after sending a 'confirmation of order' mail to the user and then send the second 'shipped order' email. currently I have this two files, tell me what changes should I make to add required delay.</p> <p>Thanks in advance.</p> <p>orders_controller.rb</p> <pre><code>def create @order = Order.new(params[:order]) @order.add_line_items_from_cart(current_cart) respond_to do |format| if @order.save Cart.destroy(session[:cart_id]) session[:cart_id] = nil OrderNotifier.received(@order).deliver #Mail after 5 miutes to inform order is Shipped OrderNotifier.delay.shipped(@order) format.html { redirect_to store_url, notice: I18n.t('.thanks') } format.json { render json: @order, status: :created, location: @order } else @cart = current_cart format.html { render action: "new" } format.json { render json: @order.errors, status: :unprocessable_entity } end end end </code></pre> <p>order_notifier.rb</p> <pre><code>class OrderNotifier &lt; ActionMailer::Base default from: 'sam ruby &lt;depot@example.com&gt;' def received(order) @order = order mail to: order.email, subject: 'Pragmatic Store Order Confirmation' end def shipped(order) @order = order mail to: order.email, subject: 'Pragmatic Store Order Shipped' end handle_asynchronously :shipped, :run_at =&gt; Proc.new { 5.minutes.from_now } end </code></pre> <p>I did the above changes to my code, </p> <p>It raise error with rake jobs:work</p> <blockquote> <p>[Worker(pid:8300)] Starting job worker [Worker(pid:8300)] Job OrderNotifier#shipped_without_delay (id=31) RUNNING [Worker(pid:8300)] Job OrderNotifier#shipped_without_delay (id=31) FAILED (0 prior attempts) with NoMethodError: undefined method <code>[]' for nil:NilClass [Worker(id:8300)] 1 jobs processed at 1.5796 j/s, 1 failed [Worker(pid:8300)] Job OrderNotifier#shipped_without_delay (id=31) RUNNING [Worker(pid:8300)] Job OrderNotifier#shipped_without_delay (id=31) FAILED (1 prior attempts) with NoMethodError: undefined method </code>[]' for nil:NilClass [Worker(pid:8300)] 1 jobs processed at 6.3007 j/s, 1 failed</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload