Maher Manoubi
Maher Manoubi

Reputation: 625

Rails Scaffold based on existing model not working

I want to generate scaffolding based on an existing model using scaffold_controller.

rails generate scaffold_controller NAME

I only get empty views, I'm not getting the fields defined in the migration. Not sure what is really going on because I use to do this and it use to work all the time in previous projects.

I'm using Rails 3.2.12, is this feature no longer available?

Thanks for the help.

Upvotes: 2

Views: 2118

Answers (3)

Maher Manoubi
Maher Manoubi

Reputation: 625

After further investigation, I think the problem is specific to my Rails installation, not sure what but if you ever get this problem, this is the workaround that I found but requires twitter bootstrap:

rails generate scaffold_controller <YOUR_MODEL_NAME>
rails g bootstrap:themed <YOUR_MODEL_NAME> -f

Hope it helps.

Upvotes: 1

TylerM
TylerM

Reputation: 160

If you want to have attributes in your views, you have pass them into the generate scaffold_controller command, like this:

generate scaffold_controller <YOUR_MODEL_NAME> attribute1 attribute2 attribute3

Then it will create views with just those attributes in them.

Upvotes: 3

Gardner Bickford
Gardner Bickford

Reputation: 1963

Your example uses scaffold_controller where as if you would like a model to be created and displayed in your views you should use just scaffold. In the case of your code example:

rails generate scaffold_controller NAME

This should become:

rails generate scaffold NAME

You will need to specify your attributes and then run

rake db:migrate

Upvotes: 0

Related Questions