0

I'm using multiple scaffolding in my testapp project.

i have created 1st scaffold like this:

rails g Post title desc:text

it was successful and created all relevant files and controller as well.

but when i made another scaffold :

testapp$ rails g scaffold product name:string information:text 'price:decimal{7,2}' stock:integer available:boolean
      invoke  active_record
      create    db/migrate/20140513062549_create_products.rb
      create    app/models/product.rb
      invoke    test_unit
      create      test/models/product_test.rb
      create      test/fixtures/products.yml
      invoke  resource_route
       route    resources :products
      invoke  inherited_resources_controller
      create    app/controllers/products_controller.rb
      invoke    erb
      create      app/views/products
      create      app/views/products/index.html.erb
      create      app/views/products/edit.html.erb
      create      app/views/products/show.html.erb
      create      app/views/products/new.html.erb
      create      app/views/products/_form.html.erb
      invoke    test_unit
      create      test/controllers/products_controller_test.rb
      invoke    helper
      create      app/helpers/products_helper.rb
      invoke      test_unit
      create        test/helpers/products_helper_test.rb
      invoke    jbuilder
      create      app/views/products/index.json.jbuilder
      create      app/views/products/show.json.jbuilder
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/products.js.coffee
      invoke    scss
      create      app/assets/stylesheets/products.css.scss
      invoke  scss
   identical    app/assets/stylesheets/scaffolds.css.scss

but when i open the controller app/controllers/products_controller.rb it is empty, why so ??

1 more thing i'm also using activeadmin, i know it has nothing to do with it.

PallavSharma
  • 439
  • 2
  • 12
  • 21
  • 1
    Seems weird.I use `Rails 3`.For me it is creating a non-empty controller with all `CRUD` methods and `code` in it. – Pavan May 13 '14 at 06:57
  • 1
    I just copied your full command and executed.It works for me. – Pavan May 13 '14 at 07:02
  • I can't reproduce your problem on a standard Rails installation following your reproduction steps. How can you be so sure, that ActiveAdmin doesn't interfere? As far as I can tell, a Rails 4 compatible ActiveAdmin has yet to be released, thus you're running a beta/pre-release version. Who knows what's not working correctly in that. – Jakob S May 13 '14 at 07:06
  • @pavan i tried doing this scaffold in new fresh project and it worked fine, may be something else has to do with it. – PallavSharma May 13 '14 at 07:24

1 Answers1

1

I can't reproduce this on a basic Rails installation:

$ rails new empty && cd empty
$ rails g scaffold Post title desc:text
$ rails g scaffold product name:string information:text 'price:decimal{7,2}' stock:integer available:boolean

After this, app/controllers/products_controller.rb has all the lines I'd expect it to have:

$ wc -l app/controllers/products_controller.rb
      74 app/controllers/products_controller.rb

That said, if I add ActiveAdmin to the Gemfile:

$ echo 'gem "activeadmin", github: "gregbell/active_admin"' >> Gemfile && bundle

and generate the scaffold:

$ rails g scaffold product name:string information:text 'price:decimal{7,2}' stock:integer available:boolean

my app/controllers/products_controller.rb contains a lot less code. It's not empty, but almost:

class ProductsController < InheritedResources::Base
end

If this is also what you're seeing, your problem comes from the fact that ActiveAdmin uses inherited_resources to do some of the heavy lifting. And you've ended up with am InheritedResource controller.

The controller should work perfectly fine, though.

Jakob S
  • 19,575
  • 3
  • 40
  • 38
  • I tried doing this scaffold in new fresh project and it worked fine, may be something else has to do with it. – PallavSharma May 13 '14 at 07:25
  • `rails g scaffold product name:string information:text 'price:decimal{7,2}' stock:integer available:boolean -c=scaffold_controller` this works perfectly, although i don't know how it works. – PallavSharma May 13 '14 at 10:11