我有能力发送电子邮件给用户,如果某个用户已请求对他们的产品感兴趣。在我的电子邮件中,我想包含某些从用户那里获得的信息,但是此刻我收到了错误,因为它声明它们未定义,尽管这些行在我的应用程序的其他地方使用。我将复制下面的电子邮件和任何介于<%%之间的内容是我想包括的内容,并且想知道是否有人可以指引我正确的方向,并告诉我哪些是正确的,哪些是不正确的。任何帮助将是美好的。我想发送的消息如下:ActionMailer邮件投递内容
Hello <%@user.username%>
The user <% current_user.username %> has registered an interest in the following product of yours:
<% @game.game_name %>
<% @game.console %>
<% @game.genre %>
The user <% current_user.usernames %> has the following games for offer:
<% current_user.game.game_name %>
<% current_user.game.game_name %>
<% current_user.game.game_name %>
To view <% current_user.username %> profile click <% link_to "here", current_user.show %>
If you wish to contact the user by email then contact the following email <% current_user.email %>.
我希望这是有道理的。为了进一步了解我所拥有的信息,我有一个用户表,其中包含用户信息和包含具有user_id外键的游戏信息的游戏表。用户拥有游戏和游戏belongs_to用户的has_many。
UPDATE
class GameTrade < ActionMailer::Base
default :from => "[email protected]"
def game_interest(user)
@user = user
@game = game
mail :to => user.email, :subject => "Game Interest"
end
end
你能在这里包括你的邮件方法吗?我想看看你是如何设置@游戏。 – 2012-03-09 17:35:18
嗨本,我用我的邮件方法更新了我的帖子。我确实在'@user = user'下面有一行说'@game = game',但这不起作用。 – user1222136 2012-03-09 18:35:03
没错,所以你不会在game_interest邮件函数中设置'@ game',所以它不会在你的视图中设置。您可以将'game'作为方法参数传递,或者以其他方式传递(如@ user.game,如果这是您应用程序中的关系) – 2012-03-09 21:10:14