开发者

Getting HTML in the controller from view template

Stackoverflow has taught me so much about what proper RESTful, MVC, GET/POST is that I am wondering how people learn to program/engineer in the past before Stackoverflow existed. ;)

Given that, here is another question on how I can do a (fairly) common procedure in the most appropriate way.

I need to generate a HTML from a view template to be used in a controller action. In that sense, it is kind of like ActiveMailer.

  1. HTML template开发者_运维知识库 in a .html.erb file
  2. Controller action with the params
  3. Get the HTML from the template to use in the controller

What is the best way to that? Pseudo code will be very much appreciated, thanks!


Perhaps I'm missing something, but do you just want render_to_string?

http://api.rubyonrails.org/classes/ActionController/Base.html#M000465

foo = render_to_string(:template => 'foo/bar', :locals => { :something => 'value' })

That basically is the same as calling render on a template, but writes to a string (foo) rather than to the http response.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜