Zain Zafar
Zain Zafar

Reputation: 1607

Custom scaffold in ruby on rails

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.

Upvotes: 1

Views: 183

Answers (2)

Rajdeep Singh
Rajdeep Singh

Reputation: 17834

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

Upvotes: 2

Leger
Leger

Reputation: 1184

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

Upvotes: 0

Related Questions