RoR: development and profiles

I am a full Rails noob and I am working on my first rail application.

I want each user to have a profile, separate from the users table, but linked by identifier. I have done this well in PHP before, but the rails syntax is new.: /

How to create a profile for each user when he registers with the device? And how do I link their users/edit page to change their profile?

+4
source share
1 answer

You Must Read This Lesson About Relationships

It is very easy to declare associations in Rails. In app/models/user.rb you can do something like this:

 has_one :user_profile 

Your user profile is another object with its own table. Just make sure that it has the foreign key user_id , and you are good to go (you should also specify belongs_to :user in your user profile model).

Now, using Devise, if you want to make sure that the profile is created after user registration, you can do something like this (still in your user model):

 after_create :create_child # Creating child Elements def create_child UserProfile.create("user_id" => id) end 

And then, if you want to associate a specific URL with the controller, see the routing guide

Hope this helps.

+7
source

All Articles