簡體   English   中英

Rails html渲染為字符串

[英]Rails html render to string

如何將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

這是我渲染視圖的方法

謝謝!

好的,我使用了render_to_string方法:

@offer_string = render_to_string(:template => 'templates/offer_template_one.html.erb', :layout => false)
# 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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM