最終我需要一個 url 編碼的行,將它傳遞給來自 web 的 whatsapp 或電報共享功能。我需要在未鏈接的資料序列之后添加換行符<br>,但我一直嘗試的它顯示為文本元素,而不是 html 元素。
我的初始代碼是
%br
- if unit.square_total.present?
Total area:
= cut_zeros(unit.square_total)
%br
- if unit.square_plot.present?
Plot area:
= cut_zeros(unit.square_plot)
%br
- if unit.square_covered.present?
Covered:
= cut_zeros(unit.square_covered)
%br
- if unit.ceiling_height.present?
Ceiling height:
= cut_zeros(unit.ceiling_height)
%br
- if unit.ceiling_basement_height.present?
Basement ceiling height:
= cut_zeros(unit.ceiling_basement_height)
%br
我現在的練習失敗了
%br
= unit.square_total? ? "Total area: #{cut_zeros(unit.square_total)}" : nil
%br
= unit.square_plot? ? "Plot area: #{cut_zeros(unit.square_plot)}" : nil
%br
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)} <br>": nil
%br
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)}" : nil
%br# last line
這段代碼釋放了很多<br>我必須避免出現的東西。
所以我必須避免所有這些%br并添加 if 陳述句true
所以我嘗試了
# series of similar lines above omitted
%br
= unit.square_total? ? "Total area: #{cut_zeros(unit.square_total)} %br": nil
= unit.square_plot? ? "Plot area: #{cut_zeros(unit.square_plot)}" %br : nil
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)} <br>": nil
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)}" : nil # last line
但一直都不是我所期望的
!我會非常高興你能給我一個建議,如何最終將此代碼(包括一系列省略的字串)帶入百分比%編碼(url 編碼)。
因為現在我在做什么,第一。創建一個代碼。執行良好,但多行第二。我將所有行加入單個長行并嘗試使所有陳述句行內作業,所以我可以簡單地使用類似這個示例的東西
但它的心是這樣的......
我最初得到的結果
圖片鏈接
幫助您了解案例
uj5u.com熱心網友回復:
使用 if 陳述句:
%br
- if unit.square_total?
= "Total area: #{cut_zeros(unit.square_total)}"
%br
- else if unit.square_plot?
= "Plot area: #{cut_zeros(unit.square_plot)}"
%br
- ...
編輯
所以,試試
%br
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)}<br>".html_safe: nil
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/475640.html
上一篇:轉換陣列Ruby
下一篇:法拉第軌道從它開始
