0

Ultimately I need an url encoded line, to pass it to whatsapp or telegram share feature from web. I need to add a line break <br> after unlinked sequence of data, but what I tried all the time it appears as text element, not html element.

My initial code is

%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

My current practiced fails

%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

this code releases a lot of <br> which I have to avoid to appear.

so I have to avoid all that %br and to be added of if statement true

so i tried

# 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

but all the time it's not what i expected

! I'll be more than happy you you could give me an advice how to bring this code (included a series of omitted strings) to percent % encoded (url encoded) finally.

Because now what I'm doing, 1st. create a code. which executes well, but multi-lined 2nd. I join all the lines to single long line and trying to make all statements working inline, so i can simply use something like this sample

But it hearts so....

The result I'm getting originally

link to image

to help you understand the case

Dan
  • 3
  • 3

1 Answers1

0

Use if statement:

%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
- ...

EDIT

so, try

%br
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)}<br>".html_safe: nil
Vi.
  • 940
  • 6
  • 24
  • It is actually what I'm avoiding to do. But, may be I'm wrong avoiding that. How to inline all that and make it url encode friendly? – Dan May 16 '22 at 10:16
  • My code is exactly as you wrote, initially. But I'm facing issue converting all that smart multiline conditional beauty to single line as whatsapp url share feature required to. – Dan May 16 '22 at 10:19
  • Ok, let's try my edit – Vi. May 16 '22 at 10:45
  • Thank you, @Joe May be you can help here? [Core issue with converting to url-encoded](https://stackoverflow.com/questions/72258145/inline-and-url-encode-for-whatsapp-the-result-of-code-sequence-obviously-multip) remain unsolved yet. – Dan May 16 '22 at 11:07