Topic: User status

Can somebody lead me or give me some hint on how to do a profile status? Like you are the user and in your profile there are status like....

In a Relationship

like those...


Re: User status

The easiest way would just be to add a relationship_status:string field to your User model:

script/generate migration AddRelationshipStatusToUser relationship_status:string

Then you'll have to add some kind of a profile form, somewhere the user can get at it, where they can select a value from a drop-down box, which you can then store in the new field.

<% form_form @user do |f| %>
<%= f.label :user, :relationship_status, "Pick your relationship status:" %>
<%= f.select_tag "relationship_status", put_your_options_here %>

If you're adding this to whatever form you've already got for when the user creates their account and you collect their name and stuff, then you won't need to do anything in your controller to also make it save this new field.  Rails is smart that way when using the scaffold-generated CRUD actions.  If you're on a separate form somewhere, submitted to a non-CRUD action, then the action your form submits to will need to explicitly grab the value of params[:relationship_status] and use it to update that field.

Re: User status

I have a profile and a user controller. User can edit the relationship in the setting, then show up in the profile bio page. How do i do that? do i need to add anything in the user controller, since all my edit setting is in the user controller.


Re: User status

Well if User objects have separate Profile objects associated with them, then make the relationship status be a field of the Profile model, rather than of the User model.

Still, what I said before applies, except now it's easier because you'll already have facilities in place for editing profiles.  Really all you're doing is adding another field to an existing model.  Do this from your command line:

$> script/generate migration AddRelationshipStatusToProfile relationship_status:string
$> rake db:migrate

Then edit all the views (the .html.erb files) in your app/views/profile directory to include the new field.  Look at how the input fields and output display is handled on the Profile's existing fields as a guide for how to add new ones.