Search code examples
ruby-on-railsscaffolding

How to create register and user profile page using scaffold or columns


I am new to Rails, and I want to make sure I start off on the right foot. So I need some clarification.

My required register fields will be Username, Email, Password, Birthday, Zip Code.

So I will be running "rails generate scaffold User name:string email:string, birthday:string zip code:string". I will then add a password_digest column to the user_spec file.

My profile fields that I will allow for users to enter after registering from their User CP is: Name, Gender, Ethnicity (option to select more than one), Email, Password, Birthday, Zipcode (not in US then list city, country), education, religion, politics, children, height, does user smoke, does user drink, career and the user about me section.

What I need confirmation is should I be generating scaffold for all of this information (User for the required information, then create another scaffold called UserProfile for the additional profile info) or should I just use columns inside the user_spec.rb for essentially all that information?


Solution

  • The actual database columns will be defined in the database migration file. You don't need to define them all in the model definition. If you build a scaffold for a model using the generator as you describe, you'll find a migration file in db/migrations which creates the columns you describe.

    It sounds like you're thinking of "scaffolds" as actual code, which is confusing. Think of scaffolds, instead, as blueprints which define the creation of model code, controller code, and view code. You don't generate scaffolds; you generate models, views, and controllers using a scaffold.