How to pass variables to render_to_string?

前端 未结 5 647
余生分开走
余生分开走 2020-12-14 06:17

Trying to do the following

@message = render_to_string ( :sender => sender, :template => \"template\" )          

But when accessing

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 06:34

    It might be the syntax you're using. Try using the :locals argument:

    @m = render_to_string :template => "template", :locals => {:sender => sender}
    

    Then you just need to access sender (without an @) as a local variable inside the template.

提交回复
热议问题