# Erb question --urgent help needed?

**URL:** <https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708>\
**Category:** Ruby\
**Created:** [June 6, 2008, 7:21am UTC](https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708 "2008-06-06T07:21:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 6, 2008, 7:21am UTC](https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708/1 "2008-06-06T07:21:22Z")

</div>

i don’t know how to explain my problem  
here i am showing it by an example

\<%  
string=“Hello Ruby ,How are you” # any String object  
width=28 # because width of the below erb tag  
is 28  
%\>  
\<%=p “%#{-width}s”%string %\>

the answer is

=\>"Hello Ruby ,How are you "

in above erb tag ("\<%=p “%#{-width}s”%string%\>") length is 28  
so i assigned width=28

here is my question  
how to define the width at dynamically for any type of erb tags ?

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 6, 2008, 10:09am UTC](https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708/2 "2008-06-06T10:09:53Z")

</div>

On Fri, Jun 6, 2008 at 7:20 AM, Pokkai D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> the answer is
> 
> =\>"Hello Ruby ,How are you "
> 
> in above erb tag (“\<%=p “%#{-width}s”%string%\>”) length is 28  
> so i assigned width=28
> 
> here is my question  
> how to define the width at dynamically for any type of erb tags ?

Can you tell what do you want to do? Why do you need to know the  
length of the tag?  
Do you want to pad the text with spaces?

What’s wrong with the following?

\<%  
string=“Hello Ruby ,How are you” # any String object  
%\>  
\<%= string %\>

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 6, 2008, 10:43am UTC](https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708/3 "2008-06-06T10:43:16Z")

</div>

Jano S. wrote:

> On Fri, Jun 6, 2008 at 7:20 AM, Pokkai D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> Can you tell what do you want to do? Why do you need to know the  
> length of the tag?  
> Do you want to pad the text with spaces?
> 
> What’s wrong with the following?
> 
> \<%  
> string=“Hello Ruby ,How are you” # any String object  
> %\>  
> \<%= string %\>

in my ROR project i need to show some details with PRINT format  
so i need like that

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 6, 2008, 10:56am UTC](https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708/4 "2008-06-06T10:56:49Z")

</div>

Jano S. wrote:

> On Fri, Jun 6, 2008 at 7:20 AM, Pokkai D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> Can you tell what do you want to do? Why do you need to know the  
> length of the tag?  
> Do you want to pad the text with spaces?
> 
> What’s wrong with the following?
> 
> \<%  
> string=“Hello Ruby ,How are you” # any String object  
> %\>  
> \<%= string %\>

actually there is a empty paper

in that paper some datas want to print for some corresponding position  
(see below…like name,phone. etc…)

## #empty paper

| |  
| name: phone: |  
| |  
| post: comment: |  
| |

| address: |
| --- |

## #paper after print

| |  
| name:mokkai phone: 919234244 |  
| |  
| post:somthing comment: nothing |  
| |

| address:full address detail here… |
| --- |

so i want to create print details in .rhtml format

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 6, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708/5 "2008-06-06T16:36:46Z")

</div>

On Fri, Jun 6, 2008 at 4:33 PM, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> …

One more suggestion: with PdfWriter, you can programmatically produce  
PDFs  
with proportional fonts, placing each text on its precise coordinates.  
You can achieve nicer output, if the required processing is feasible.

J.

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [June 6, 2008, 4:34pm UTC](https://www.ruby-forum.com/t/erb-question-urgent-help-needed/139708/6 "2008-06-06T16:34:24Z")

</div>

On Fri, Jun 6, 2008 at 10:55 AM, Pokkai D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> | post: comment: |  
> | |
> 
> | address:full address detail here… |
> | --- |
> 
> so i want to create print details in .rhtml format

I can’t help you with a general solution, I guess the way you startes  
is the way to go.  
Though:

1. you don’t need p there - instead of \<%=p just leave there \<%=
2. create a helper function to pad the string to desired width

def pad(lenght, data)  
data.to\_s.just(length)  
end

then you can do:

\<%= pad 28, name %\>\<%= pad 15, phone\_number %\> etc.

I quite can’t imagine what you mean by “define the width at  
dynamically for any type of erb tags”.  
Don’t worry though, the problem is most probably somewhere between my  
keyboard and my chair 😉

J.
