# Newbie eRuby site design question

**URL:** <https://www.ruby-forum.com/t/newbie-eruby-site-design-question/129579>\
**Category:** Ruby\
**Created:** [February 19, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/newbie-eruby-site-design-question/129579 "2008-02-19T20:27:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [February 19, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/newbie-eruby-site-design-question/129579/1 "2008-02-19T20:27:54Z")

</div>

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

 ![](https://www.ruby-forum.com/public/banners/<%=banner%>)

 [menu] 

\<%=title%\>

\<%=message%\>

 ![](https://www.ruby-forum.com/public/images/<%=image%>)

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

---

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [February 20, 2008, 12:27am UTC](https://www.ruby-forum.com/t/newbie-eruby-site-design-question/129579/2 "2008-02-20T00:27:40Z")

</div>

Peter W. wrote:

> //in config//
> 
> 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

---

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [February 20, 2008, 12:35am UTC](https://www.ruby-forum.com/t/newbie-eruby-site-design-question/129579/3 "2008-02-20T00:35:00Z")

</div>

Justin C. wrote:

> Peter W. wrote:
> 
> > //in config//
> > 
> > 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

---

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [February 20, 2008, 12:44am UTC](https://www.ruby-forum.com/t/newbie-eruby-site-design-question/129579/4 "2008-02-20T00:44:52Z")

</div>

Solved 🙂

---

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [February 20, 2008, 6:43am UTC](https://www.ruby-forum.com/t/newbie-eruby-site-design-question/129579/5 "2008-02-20T06:43:41Z")

</div>

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