erb question --urgent help needed?

P

Pokkai Dokkai

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 ?
 
J

Jano Svitok

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 ?


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

Pokkai Dokkai

Jano said:
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
 
P

Pokkai Dokkai

Jano said:
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...... |
 
J

Jano Svitok

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

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

Jano Svitok


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top