5
我有一个场景,我想用我的JSON传回长消息。我宁愿将可以呈现到我的JSON中的erb模板放在一起,而不是用字符串连接写出来。下面是我目前正试图代码:在RABL模板中渲染ERB模板
object @invitation
node(:phone_message) do |invitation|
begin
old_formats = formats
self.formats = [:text] # hack so partials resolve with html not json format
view_renderer.render(self, {:template => "invitation_mailer/rsvp_sms", :object => @invitation})
ensure
self.formats = old_formats
end
end
一切正常第一次运行这些代码,但是,我遇到问题我第二次运行它,因为它说,有一个丢失的实例变量(我认为这是第一次运行时生成和缓存的)。
未定义的方法 _app_views_invitation_mailer_rsvp_sms_text_erb___2510743827238765954_2192068340 为#(::的ActionView ::模板错误)
有没有更好的办法来渲染ERB模板到Rabl的?