Ruby on rails Rails 4-ActionMailer帮助程序未定义的方法'session';
我是Rails新手,很难理解为什么从ActionMailer调用我的助手模块时无法工作。我从不同的部分调用相同的方法,效果很好。问题不在于方法,而在于我的会话变量(session[:geo])——它表示“未定义的方法‘session’” 这是我的代码,任何建议都非常感谢 products_helper.rbRuby on rails Rails 4-ActionMailer帮助程序未定义的方法'session';,ruby-on-rails,Ruby On Rails,我是Rails新手,很难理解为什么从ActionMailer调用我的助手模块时无法工作。我从不同的部分调用相同的方法,效果很好。问题不在于方法,而在于我的会话变量(session[:geo])——它表示“未定义的方法‘session’” 这是我的代码,任何建议都非常感谢 products_helper.rb def isUserLocal? session[:geo] #true or false end def itemTotalPrice(item) if self.isU
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
订单通知程序-ActionMailer
class OrderNotifier < ActionMailer::Base
helper :Products #helpers are not available in ActionMailers by default
在浏览器中,您可以有一个会话。在电子邮件中,你不能。它按原样发送。电子邮件中没有会话。您是否检查了前面的问题?是的,我包括助手。所有方法都可以正常工作会话变量是唯一不起作用的。Misha-正如您在上面看到的,ActionMailer不调用Helper模块,它呈现一个分部,分部调用该方法。我想你说的有道理吧?下面是我在create方法(表单提交)中调用actionmail的方式:OrderNotifier.received(@order.deliver)#向用户发送确认电子邮件
<%= render @order.line_items -%>
number_to_currency(itemTotalPrice(line_item))