Question

I am creating my first rails application and I am stuck in a problem. I have 2 models : Album and Artist. I have created corresponding table in mysql database with several fields. The problem is when I generate a scaffold by : "rails generate scaffold Album" it generates a scaffold, but controller and view doesn't have any field which is present in my DB.

Actually I am learning rails from the Lynda course. In those videos tutor first creates several tables with columns. Then he simply generate the scaffold by above mentioned command (with script/generate).He has all the fields in the view while I have nothing. I want that my scaffold also creates all related fields like those of tutor's!

I am using rails 4.0 version on Windows.

Was it helpful?

Solution 2

You need to specify fields while generating scaffold: rails generate scaffold User name:string email:string

OTHER TIPS

Firstly, you don't need to create the table and fields explicitly in the database, after generating scaffold on running rake db:migrate table fields will be automatically created.

Secondly, rails generate scaffold Album will generate an empty scaffold,

You need to pass name of the field along with it datatype with scaffold generation script

e.g.

rails generate scaffold Album name:string type:string
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top