[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie eRuby site design question

Peter Woodsky

2/19/2008 7:28:00 PM

Hi list
I'm designing a dynamic site using eruby/mod_ruby and so far its coming
together pretty well but I'm stuck on something and could use some help.
I have a config file (out of the web root) that I'm using to set params
and vars. I'd rather not embed a db select into my pages but rather have
it in my config and just call the data from a var but nothing I've tried
works.

example

//in config//
row = dbh.select_one("select banner,title,message,image from contents;")
banner = "#{row[0]}"; title = "#{row[1]}"; message = "#{row[2]}"; image
= "#{row[3]}"

//in web page//
<div id="header">
<img src="/public/banners/<%=banner%>" width="1003" height="196"
border="0">
</div>
<div id="page">
<div id="colOne">
[menu]
</div>
<div id="colTwo">
<div id="title"><%=title%></div>
<div id="message"><%=message%></div>
</div>
<div id="colThree"><img src="/public/images/<%=image%>"
border="0"></div>
</div>

How do I define the output from the select so I can use it in my page?
In the above example I get errors that banner, title, message, image are
not defined.

Any help is appreciated.

Thanks!!
--
Posted via http://www.ruby-....

4 Answers

Justin Collins

2/19/2008 11:27:00 PM

0

Peter Woodsky wrote:
> Hi list
> I'm designing a dynamic site using eruby/mod_ruby and so far its coming
> together pretty well but I'm stuck on something and could use some help.
> I have a config file (out of the web root) that I'm using to set params
> and vars. I'd rather not embed a db select into my pages but rather have
> it in my config and just call the data from a var but nothing I've tried
> works.
>
> example
>
> //in config//
> row = dbh.select_one("select banner,title,message,image from contents;")
> banner = "#{row[0]}"; title = "#{row[1]}"; message = "#{row[2]}"; image
> = "#{row[3]}"
>
> //in web page//
> <div id="header">
> <img src="/public/banners/<%=banner%>" width="1003" height="196"
> border="0">
> </div>
> <div id="page">
> <div id="colOne">
> [menu]
> </div>
> <div id="colTwo">
> <div id="title"><%=title%></div>
> <div id="message"><%=message%></div>
> </div>
> <div id="colThree"><img src="/public/images/<%=image%>"
> border="0"></div>
> </div>
>
> How do I define the output from the select so I can use it in my page?
> In the above example I get errors that banner, title, message, image are
> not defined.
>
> Any help is appreciated.
>
> Thanks!!
>

Try using ERuby.import("config.rb") at the top of your page to parse and
run the config file first.

-Justin

Peter Woodsky

2/19/2008 11:35:00 PM

0

Justin Collins wrote:
> Peter Woodsky wrote:
>> //in config//
>> <div id="colOne">
>> How do I define the output from the select so I can use it in my page?
>> In the above example I get errors that banner, title, message, image are
>> not defined.
>>
>> Any help is appreciated.
>>
>> Thanks!!
>>
>
> Try using ERuby.import("config.rb") at the top of your page to parse and
> run the config file first.
>
> -Justin

Hi Justin
Thanks for the response. I already use "require" which does the job for
importing and setting most of the vars. It however does not work with
the data from the db.

Regards

--
Posted via http://www.ruby-....

Peter Woodsky

2/19/2008 11:45:00 PM

0

Solved :)
--
Posted via http://www.ruby-....

Arlen Cuss

2/20/2008 5:43:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Just for the record, you can probably substitute:

banner = "#{row[0]}"; title = "#{row[1]}"; message = "#{row[2]}"; image
= "#{row[3]}"

with:

banner, title, message, image = row

If it gets snarky about them not being strings (for whatever reason?),
row.map {|e| e.to_s}.