0

I'm new to Rails and I'm having a hard time understanding why my helper module doesn't work when called from the ActionMailer. I'm calling the same method from a different partial and it works fine. The problem is not so much the method but my session variable (session[:geo]) - it says "undefined method `session'".

here is my code any suggestion is much appreciated

products_helper.rb

def isUserLocal?
    session[:geo] #true or false
end

def itemTotalPrice(item)
    if self.isUserLocal?
        item.line_item_us_total_price
    else
        item.line_item_w_total_price
    end
end

order-notifier - ActionMailer

   class OrderNotifier < ActionMailer::Base

   helper :Products #helpers are not available in ActionMailers by default

received.html.erb

   <%= render @order.line_items -%>

_line_items.html.erb

   number_to_currency(itemTotalPrice(line_item))
Marc Nunes
  • 238
  • 3
  • 13
  • In a browser you can have a session. In an email you can't. It is sent as-is. There is no such thing as a session in an email. – Mischa Sep 03 '13 at 01:51
  • Have you checked this previous question? http://stackoverflow.com/questions/4937208/access-helpers-from-mailer – Marcelo De Polli Sep 03 '13 at 01:53
  • Yes I'm including the helper. All methods work fine the session variable is the only thing that doesn't work. Mischa - as you can see above the ActionMailer does not call the Helper module, it renders a partial and the partial make the call to the method. I guess it makes sense what you're saying anyway around it? Here is how I'm calling my ActionMailing inside my create method (form submission): OrderNotifier.received(@order).deliver #send confirmation email to user – Marc Nunes Sep 03 '13 at 02:20

0 Answers0