Generate scaffold not generating views


#1

Hi!
Sorry for the newbie question…

I’m following the depot example in AgileWebDevelopmentWithRails.
Stangelly, generating scaffolding using the command (page 53):

./script/generate scaffold Product Admin

does not generate any .rhtml file, but just:

   exists  app/controllers/
   exists  app/helpers/
   exists  app/views/admin
   exists  test/functional/

dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/product.rb
identical test/unit/product_test.rb
identical test/fixtures/products.yml

Any suggestions?

Thanks,
jb


#2

Hi Jose,

From the listing you included below, I’d say Rails is telling you that views for the Admin controller already exist (i.e., line 3 shows 'exists app/views/admin"). I thought the scaffold command would just overwrite anything that was already there, but maybe that’s been changed.

hth,
Bill
----- Original Message -----
From: José Bonnet
To: removed_email_address@domain.invalid
Sent: Thursday, April 20, 2006 10:45 AM
Subject: [Rails] generate scaffold not generating views

Hi!
Sorry for the newbie question…

I’m following the depot example in AgileWebDevelopmentWithRails.
Stangelly, generating scaffolding using the command (page 53):

./script/generate scaffold Product Admin

does not generate any .rhtml file, but just:

    exists  app/controllers/
    exists  app/helpers/
    exists  app/views/admin
    exists  test/functional/
dependency  model
    exists    app/models/
    exists    test/unit/
    exists    test/fixtures/
 identical    app/models/product.rb
 identical    test/unit/product_test.rb
 identical    test/fixtures/products.yml

Any suggestions?

Thanks,
jb



Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#3

Well, Bill, that’s the problem: neverthless, that directory is empty…
jb


#4

José,

Are you sure that’s all the output when you try to generate the
scaffold? It
should also try to generate controllers, etc.

You might check to see that you have the products table created in the
database, because the generator will abort while still incomplete if you
don’t have the table.

Jeff


#5

Just in case: try deleting the /admin folder.


#6

Hi, Jeff!
Yes, I’ve got the table:
sqlite> .tables
products
sqlite> .schema
CREATE TABLE products (id integer primary key, title text,
description text, image_url text, price numerical);

Yes, I’ve generated the model (product) and the controller (admin).
jbonnet$ ls -lisap app/controllers/ app/models/
app/controllers/:
total 24
2721789 0 drwxr-xr-x 5 jbonnet jbonnet 170 Apr 20 17:51 ./
2721788 0 drwxr-xr-x 6 jbonnet jbonnet 204 Apr 20 14:46 …/
2726461 8 -rw-r–r-- 1 jbonnet jbonnet 70 Apr 20 17:51
admin_controller.rb
2721825 8 -rw-r–r-- 1 jbonnet jbonnet 216 Apr 20 14:46
application.rb
2726411 8 -rw-r–r-- 1 jbonnet jbonnet 72 Apr 20 17:46
product_controller.rb

app/models/:
total 16
2721791 0 drwxr-xr-x 4 jbonnet jbonnet 136 Apr 20 18:01 ./
2721788 0 drwxr-xr-x 6 jbonnet jbonnet 204 Apr 20 14:46 …/
2726664 8 -rw-r–r-- 1 jbonnet jbonnet 35 Apr 20 18:01 mdl.rb
2724171 8 -rw-r–r-- 1 jbonnet jbonnet 455 Apr 20 16:22 product.rb

Neverthless:
jbonnet$ ./script/generate scaffold product admin
exists app/controllers/
exists app/helpers/
exists app/views/admin
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
skip app/models/product.rb
identical test/unit/product_test.rb
identical test/fixtures/products.yml

So, no views:-(
jb


#7

Hi, Adam!
Just did it:

  1. removed …/views/admin
  2. jbonnet$ ./script/generate scaffold Product Admin
    exists app/controllers/
    exists app/helpers/
    create app/views/admin
    exists test/functional/
    dependency model
    exists app/models/
    exists test/unit/
    exists test/fixtures/
    create app/models/product.rb
    identical test/unit/product_test.rb
    identical test/fixtures/products.yml

That is, files in …/views/admin don’t get generated.
I’m using the following versions:
jbonnet$ rails -v
Rails 1.1.2
jbonnet$ ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]

thanks,
jb


#8

Ok, I’ve found it!
I’ve upgraded to ruby 1.8.4, deleted …/app/views, and rerun

./script/generate scaffold Product Admin

Now I have all the files I need:
jbonnet$ ./script/generate scaffold Product Admin
exists app/controllers/
exists app/helpers/
create app/views/admin
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
skip app/models/product.rb
identical test/unit/product_test.rb
identical test/fixtures/products.yml
create app/views/admin/_form.rhtml
create app/views/admin/list.rhtml
create app/views/admin/show.rhtml
create app/views/admin/new.rhtml
create app/views/admin/edit.rhtml
create app/controllers/admin_controller.rb
create app/helpers/admin_helper.rb
create app/views/layouts/admin.rhtml

Thanks a lot!
jb


#9

Yes, I’ve generated the model (product) and the controller (admin).

I’m not sure what you mean by this, but if you mean that you’ve done:

./script/generate controller Admin

When you generate a controller it creates an empty /view/ folder that won’t be overwritten by future generates. Whereas if
you do:

./script/generate scaffold Product Admin

It creates a controller, a model, and the /view/admin files.