# Basic Help - non-standard table-name

**URL:** <https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409>\
**Category:** Rails\
**Created:** [February 18, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409 "2008-02-18T12:02:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 18, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409/1 "2008-02-18T12:02:54Z")

</div>

Hi all,

I’m trying to get my first real ruby on rails app started, but I have  
two basic problems. The book I’m using is pre 2.0; also I need to use a  
pre-existing table whose name is not per ruby convention - eg instead of  
a table called “products”, it’s called “tbl\_products”. The database I’m  
running is MySql.

I’ve tried searching for a 2.0 standard way to create what I need for a  
CRUD (Create, Remove, Update, Delete) interface to the table, but i keep  
finding conflicting instructions and haven’t got anything to work yet.

I know this is a really noob question, but I think that since 2.0 seems  
to have introduced so many changes, it’s harder to find a reliable guide  
to getting started.

So, would one of you good people be able to show me (and the rest of us  
noobs) the 2.0 way to create an initial CRUD MVC where the tablename is  
not as per convention.

many thanks.

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 18, 2008, 1:46pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409/2 "2008-02-18T13:46:56Z")

</div>

> So, would one of you good people be able to show me (and the rest of us  
> noobs) the 2.0 way to create an initial CRUD MVC where the tablename is  
> not as per convention.

I assume that the name of the model in Rails is Product and that you  
have a product.rb file?

If so, add the following to the top of the model:

set\_table\_name “tbl\_products”

This should be all you need to do.

Best Regards

Robin

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 18, 2008, 3:49pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409/3 "2008-02-18T15:49:04Z")

</div>

Robin F. wrote:

> set\_table\_name “tbl\_products”

Thanks for the tip. I could have sworn I tried that last night. Never  
mind!

I added the above line to the model, and this time instead of throwing  
up the error, the browser just spins and spins.

The products table is quite large - 250,000 ish records. So, I repeated  
the above steps on a smaller table as a proof of concept. This time it  
came back quite quickly with a “no route” message. I guess this is the  
2.0 difference in scaffolding, so I’m happy to try loading a third-party  
component for this. I’m looking at activescaffold.

I’m still concerned with the browser spinning for minutes (and nothing  
appearing in the WEBrick logfile) when I try to access the products.  
Does this mean that it’s trying to load the entire tbl\_products table  
into an array someplace before trying to do the routing? If so, I am  
very worried about performance.

I guess I could try deleting most of the products from the dev database  
and see how i get on.

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 18, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409/4 "2008-02-18T16:15:24Z")

</div>

On 18 Feb 2008, at 14:49, Just S. wrote:

> I added the above line to the model, and this time instead of throwing  
> component for this. I’m looking at activescaffold.
> 
> I’m still concerned with the browser spinning for minutes (and nothing  
> appearing in the WEBrick logfile) when I try to access the products.  
> Does this mean that it’s trying to load the entire tbl\_products table  
> into an array someplace before trying to do the routing? If so, I am  
> very worried about performance.

It certainly shouldn’t do and has never done in my experience.  
Something a bit fishy is going on, but it’s hard to say without seeing  
anything you’ve done.

Fred

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 18, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409/5 "2008-02-18T16:25:27Z")

</div>

Frederick C. wrote:

> Something a bit fishy is going on, but it’s hard to say without seeing  
> anything you’ve done.
> 
> Fred

Thanks for that, Fred. I’ll paste some code when I’m free from the  
firewall restrictions here.

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 18, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409/6 "2008-02-18T16:54:27Z")

</div>

Before you go and delete stuff, try doing some console work. (script/  
console in your app’s root). If your model has been done correctly,  
I’m assuming you’ve called it products, then you should be able to do  
this: products = Product.find(:all, :limit=\>5) and that should return  
the first 5 records of the products table…

obviously with something as big as 250,000 you’re not going to want to  
load it all at one time. You are going to want to look into some sort  
of pagination rather than massive loading to speed up your database.

On Feb 18, 9:25 am, Just S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![justsomeone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@justsomeone](https://www.ruby-forum.com/u/justsomeone)\
**Post date:** [February 18, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/basic-help-non-standard-table-name/129409/7 "2008-02-18T16:01:45Z")

</div>

Just S. wrote:

> I’m looking at activescaffold.

Whoops! I mean streamlined.
