2
votes

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.

3

3 Answers

3
votes

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.

1
votes

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.

0
votes

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