简体   繁体   中英

How to call render on a view from inside an action?

I want to get the rendered response from the action BEFORE it returns, so something like:

def test

  my_html = # RENDER VIEW HERE AND ASSIGN TO VARIABLE


  render :text => my_html

end

How can I do this?

You could use render_to_string

def test
  my_html = render_to_string(:action => :show)

  render :text => my_html
end

render_to_string accepts all options that render does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM