如何将HTML视图呈现为字符串(保存在数据库中)以便能够在rails中将其呈现回来?
def show_offer
respond_to do |format|
format.html { render 'offer_template_one', :layout => 'templates'}
format.pdf do
render :pdf => 'oferta',
:template => 'templates/show_offer.pdf.erb',
:layout => "layouts/templates.html.erb",
:save_to_file => Rails.root.join('public', "Oferta.pdf")
end
end
end
这是我渲染视图的方法
谢谢!
答案 0 :(得分:8)
好的,我用它来处理render_to_string方法:
@offer_string = render_to_string(:template => 'templates/offer_template_one.html.erb', :layout => false)
答案 1 :(得分:1)
# Renders the clear text "hello world" with status code 200
render :text => "hello world!"
# Renders the clear text "Explosion!" with status code 500
render :text => "Explosion!", :status => 500
# Renders the clear text "Hi there!" within the current active layout (if one exists)
render :text => "Hi there!", :layout => true
# Renders the clear text "Hi there!" within the layout
# placed in "app/views/layouts/special.r(html|xml)"
render :text => "Hi there!", :layout => "special"