views:

461

answers:

1

Hi!

I have a database with tables. I want to create a model in my Rails app from existing table. As i know, such functionality is available, and is done as follows:

script/generate scaffold model_name --skip-migration


Of course, i defined my database in database.yml file. Scaffold generated for me a model with controller and views. My table name is not as it must be for Rails(it is incorrect, not following conventions), i added set_table_name to my controller. But, when i am calling the index method, on my page i have only set of # symbols, but not a data from database. In my index.html.erb i have only generated code by scaffold. How can i print out my database data?

+1  A: 

Have you generated a schema file from your existing database? If you run the command

rake db:schema:dump

and then re-generate your scaffold this should fix the problem.

Additionally you may wish to check out Dr Nic's Magic Model generator. This will generate models for all of your existing tables and attempt to guess the relationships. This will probably not work if your table naming is not understandable by rails.

UPDATE

I do not generally use the default scaffold however I have tested this myself and it appears that if you skip the migration and do not pass any column name/type pairs then the scaffold generator will not create anything in the template to render the columns.

You have two choices here either

  1. Pass in the column name pairs as well as skip-migration or
  2. Download Ryan Bates Nifty Scaffold generator which will create the scaffold with the column names even if you specify --skip-migration
Steve Weet
I have postgresql database, and i generated schema. Problem not solved.
Yurish
Thanks! I`ll try, but it seems, that you are right!
Yurish