1
votes

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?

3
I would expect spec/models/user_spec.rb to be an Rspec test for the User model found in app/models/user.rb. If you start using Rspec to test your code (and you don't have to use Rspec, but you should test) and you're using names like *_spec.rb elsewhere, you might find those names confusing. - pjmorse

3 Answers

1
votes

The idea is to keep all the fields in one table. This can be done using migration easily.

After adding all the fields including Username, Email, Password, Birthday, ZipCode,Name, Gender, Ethnicity (option to select more than one), education, religion, politics, children, height, does user smoke, does user drink, career and the user about me section.

Then you can imply the condition after login and before login to show/hide the fields according to what you want.

The general way to do that is:

if current_user

//show the fields after login
else
//show the fields before login
end

Note that it is a general idea of how you could do that. However you can use it anywhere in your code in any view.

0
votes

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.

0
votes

I am fairly new to rails, but I would not recommend the Scaffold option. You would do better to generate a User model and Users controller from the command line with desired fields, and then create your views as you need them.

Scaffolding will probably give you more than what you need and lead to confusion/problems down the road.

You should check out Michael Hartl's "Learn Rails by Example" (free as an ebook!). Even if you don't want to work through it, he guides readers through building a Twitter app and I think reading some of the chapters would be helpful to you. Good luck!