Basic Help - non-standard table-name

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.

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

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

Just Someone wrote:

I'm looking at activescaffold.

Whoops! I mean streamlined.

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

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

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

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.