填充变量
问题描述:
我有这种功能,在浏览器的游戏我正在做:填充变量
def sendAllianceInvitationMessage(invited_user, alliance)
subject = 'Alliance Invitation'
body = 'You have received an invitation to join the alliance ' + alliance.name + '.'
body += ' Please visit the Alliance Menu in order to accept or reject alliance invitations.'
current_user.sendMessage(invited_user, subject, body, 'alliance invitation')
end
我真的不舒服,在这种方式加载身体的想法。是否有可能有一个部分接收参数(如代码中的alliance.name),生成正文内容并将其传递给sendMessage中使用的字符串变量?
答
可以渲染的部分,做为了做到这一点
body = render_to_string('send_alliance_invitation_message')
你只需要通过你的ARGS像一个视图,你得到的结果在你的身体的对象
伟大谢谢! – Spyros 2011-02-01 10:21:25