inherited_resources icon indicating copy to clipboard operation
inherited_resources copied to clipboard

any way to permit 'rails scaffold' to work normally if inherited_resources used by another gem?

Open jpwynn opened this issue 14 years ago • 16 comments

I installed ActiveAdmin, which uses InheritedResources, which now means when I try to generate plain old rails scaffolding, it does not create CRUD actions and creates a controller based on InheritedResources.

For those of us who need the ability to create normal rails scaffolds, is there a way to have inherited_resources NOT override the default scaffolding when we manually scaffold new models?

jpwynn avatar Jan 19 '12 00:01 jpwynn

This is how InheritedResources changes this configuration.

You should be able to do the same in your app, configuring back to the default :scaffold_controller, by adding this to your application.rb file:

config.app_generators.scaffold_controller = :scaffold_controller

That should work.

carlosantoniodasilva avatar Jan 19 '12 01:01 carlosantoniodasilva

Though that did not work. I tried adding

config.app_generators.scaffold_controller = :scaffold_controller

to config/application.rb, then to config/environments/development.rb. In both cases, running 'rails g scaffold' produced the same empty controller with a class based on InheritedResources::Base instead of ApplicationController

jpwynn avatar Jan 19 '12 01:01 jpwynn

here is something that does work, although it would be much better to change the setting once in a config file per your suggestion, if we can find the right setting. But for a manual override, this works:

rails g scaffold Foobar name:string -c=scaffold_controller

If anyone knows how to revert to scaffold_controller being the default, please chime in.

jpwynn avatar Jan 19 '12 01:01 jpwynn

Weird, setting the config in your application should have worked fine. Could you please send which Rails and IR (or ActiveAdmin) version you're using?

carlosantoniodasilva avatar Jan 19 '12 11:01 carlosantoniodasilva

I have rails 3.1.3, IR gem 1.2.2, activeadmin gem 0.3.4, running on windows xp sp3, doing everything via bash shell. rake is 0.8.7.

jpwynn avatar Jan 19 '12 19:01 jpwynn

Bump. I am having the same issue.

jontonsoup avatar Feb 11 '12 00:02 jontonsoup

It seemed fixed now. Using rails 3.2.1 , activeadmin 0.4.0. Add the line to application.rb got it fixed.

zetachang avatar Feb 11 '12 10:02 zetachang

Thanks. I was using rails 3.1.x. Upgrading fixed it.

jontonsoup avatar Feb 12 '12 05:02 jontonsoup

In Rails 4 this still works.

rdetert avatar Mar 27 '14 07:03 rdetert

Hey guys, I'm using Rails 5.2 and ruby 2.5.1 and when running the scaffold generator like rails g scaffold agreement folio customer:references. I still getting my controller inheriting from InheritedResources::Base.

Does this fix config.app_generators.scaffold_controller = :scaffold_controller will be part of the RubyGems version for ActiveAdmin? Or is it better to use the AA git version?

alexventuraio avatar Jun 26 '18 16:06 alexventuraio

Hola chicos, estoy usando Rails 5.2 y ruby 2.5.1 y cuando ejecuto el generador de andamios como rails g scaffold agreement folio customer:references. Todavía tengo mi controlador heredado de InheritedResources::Base.

¿Esta solución config.app_generators.scaffold_controller = :scaffold_controllerserá parte de la versión de RubyGems para ActiveAdmin? ¿O es mejor usar la versión git AA?

Yes.

Moriort avatar Nov 10 '18 05:11 Moriort

@jpwynn's solution to use -c=scaffold_generator works like a charm even in Rails 6. Thank you very much!

simondebbarma avatar May 02 '20 19:05 simondebbarma

-c=scaffold_generator didn't work for me, but placing this config line into my app:

config.app_generators.scaffold_controller = :scaffold_controller

and running:

rails g scaffold report start_at:date end_at:date portfolio_name:string -c=scaffold_controller

did work. It's very frustrating that ActiveAdmin breaks Rails default scaffold by doing this.

KelseyDH avatar May 29 '20 00:05 KelseyDH

@KelseyDH I think you have to use either one or the other but not both fixes together. The config file fix is a one-time fix, once you set that up you do not need to do anything else for each and every scaffold you want to create.

config.app_generators.scaffold_controller = :scaffold_controller

The command-line argument/flag is meant for overriding the app configuration only once for the actual command that you are running at that time. That means that you need to add that flag to your scaffold generator command every single time you run it.

rails g scaffold report start_at:date end_at:date portfolio_name:string -c=scaffold_controller
rails g scaffold url domain:string -c=scaffold_controller
rails g scaffold user name:string -c=scaffold_controller
...

alexventuraio avatar May 29 '20 01:05 alexventuraio

That's why I should recommend to go with the config file and forget about any further flag on the command-line.

alexventuraio avatar May 29 '20 01:05 alexventuraio

what about existing scaffolds? old scaffolds are not working after installing activeadmin even if i use config.app_generators.scaffold_controller = :scaffold_controller

What do you mean by existing scaffolds, old scaffolds ?

alexventuraio avatar Jul 28 '20 16:07 alexventuraio