# Formatting looping display from mySQL table

**URL:** <https://www.ruby-forum.com/t/formatting-looping-display-from-mysql-table/123944>\
**Category:** Rails\
**Created:** [December 22, 2007, 1:05pm UTC](https://www.ruby-forum.com/t/formatting-looping-display-from-mysql-table/123944 "2007-12-22T13:05:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![agorilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@agorilla](https://www.ruby-forum.com/u/agorilla)\
**Post date:** [December 22, 2007, 1:05pm UTC](https://www.ruby-forum.com/t/formatting-looping-display-from-mysql-table/123944/1 "2007-12-22T13:05:35Z")

</div>

Hi

I’m a noob to RoR. I have everything setup but can’t figure out to get  
the list display as I would like. I’m sure this is very simple stuff. I  
just haven’t figured it out yet ☹

I hope someone can point me in the right direction 🙂

I have a mysql table “websites”.

In it I have the following columns - Name, Url, Banner, Description

I created “ruby script/generate controller website” (& the model too)  
and inserted

model :website  
scaffold :website

have not changed the website\_controller.rb (well that’s not strictly  
true I tried but couldn’t get it to work so reverted back).

Website/list.rhtml is also the default scaffold build.

So I get a nice view of the content of the websites table, however I  
want to format this output into something useful.

Something like a looping version of this.

\<img src=“Banner” alt"Name" /\>

Description

It seems the default view grabs everything in one block where as I want  
to grab and use the individual columns.

I don’t know enough of the terminology to to a search to find out how to  
do such a thing and most of the tutorials I have gone through seem to  
display the default scaffold views.

If someone can give me some pointers or even a link to a relevant  
tutorial on how to set up such a thing I would be very grateful.

Cheers

---

<div class="post-metadata">

**Author:** ![agorilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@agorilla](https://www.ruby-forum.com/u/agorilla)\
**Post date:** [December 22, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/formatting-looping-display-from-mysql-table/123944/2 "2007-12-22T13:15:35Z")

</div>

Your controller:

def list  
@websites = Website.find(:all)  
end

Your view (list.html.erb):

\<% for website in @websites %\>  
…stuff for each website here, referencing the column values as  
website.column.  
\<% end %\>

On Dec 22, 2007 10:35 PM, Bill G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## Cheers
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![agorilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@agorilla](https://www.ruby-forum.com/u/agorilla)\
**Post date:** [December 22, 2007, 1:32pm UTC](https://www.ruby-forum.com/t/formatting-looping-display-from-mysql-table/123944/3 "2007-12-22T13:32:34Z")

</div>

Oh that’s for Rails 2.0, if you’re using it. instead of it being called  
list.rhtml it’s now list.html.erb. This is so you can use different  
formats  
with maintaining an easy to follow naming schema. Nothing you’d have to  
worry about. Yet.

On Dec 22, 2007 11:00 PM, Bill G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > \<% end %\>
> > 
> > > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).  
> > > –  
> > > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![agorilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@agorilla](https://www.ruby-forum.com/u/agorilla)\
**Post date:** [December 22, 2007, 1:30pm UTC](https://www.ruby-forum.com/t/formatting-looping-display-from-mysql-table/123944/4 "2007-12-22T13:30:39Z")

</div>

Nice one - thanks Ryan. I knew it was simple. There is no stopping me  
now 🙂

One more question. What is the “.erb” in “(list.html.erb)” below?

Cheers

Ryan B. wrote:

> Your controller:
> 
> def list  
> @websites = Website.find(:all)  
> end
> 
> Your view (list.html.erb):
> 
> \<% for website in @websites %\>  
> …stuff for each website here, referencing the column values as  
> website.column.  
> \<% end %\>
> 
> On Dec 22, 2007 10:35 PM, Bill G.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > ## Cheers
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> Ryan B.  
> [http://www.frozenplague.net](http://www.frozenplague.net)  
> Feel free to add me to MSN and/or GTalk as this email.
