Rails and development - adding a login field

I created a secure login blog using the Devise plugin and its operation. I'm going to add an extra username field during registration, and then the posts in this article display this information. How can I achieve this so that the username gets into db - will any help on the code be appreciated?

User names must be unique, but I will talk about this later.

+3
source share
3 answers

As a wiki sez developer:

Create Transfer

rails generate migration add_username_to_users username:string

Start the migration

rake db:migrate

Change the user model and add the username to attr_accessible

 attr_accessible :username

more details here

For uniqueness, you can simply perform a check on the user model

, !

+8

, 2 .

, :

: , @article, nil. Rails User, -, nil.

_article, .

, :

"email" "username", ,

.. , , . , user.username

0
  • belongs_to :user article.rb has_many :articles user.rb
  • update article migration to include user_id: integer field (or use t.references :user)
  • update your ArticleController # create an action to use current_user.create_articleorbuild_article
  • be sure to call authenticate_user! before_filter for: creating an action before_filter: authenticate_user !, only =>: only => [: new ,: create ,: edit ,: update ,: destroy]

ref: http://guides.rubyonrails.org/association_basics.html

0
source

All Articles