简体   繁体   English

如何从动作内部调用视图上的渲染?

[英]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 您可以使用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. render_to_string接受render的所有选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在当前视图内渲染另一个页面(Controller Action + View) - How to render another page (Controller Action + View) inside current view Rails 3:如何从另一个控制器的视图呈现动作 - Rails 3: How to render an action from another controller's view 如何从ruby-on-rails中的视图内部呈现索引视图 - How to render the index view, from inside a view in ruby-on-rails 如何调用动作,从js传递值到该动作并在Rails 3的页面上重新呈现js? - How can I call an action, pass a value to the action from js and re-render the js on a page in rails 3? 如何从同一控制器内的另一个动作呈现动作并传递参数 - How to render action from another action inside same controller and pass parameters 如何调用控制器动作,然后将其渲染为ror中的字符串? - How to call controller action and then render it to a string in ror? 如何在 Vuex 中调用 action inside action - How to call action inside action in Vuex 如何将erb模板渲染为字符串内部动作? - How to render erb template to string inside action? 如何确定在控制器操作中呈现哪个视图 - How to determine which view to render in a controller action 如何从邮件内的链接调用销毁操作 - How to call destroy action from a link inside a Mail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM