I am creating a Ruby on Rails application and I am trying to create / log in / log out.
This is a diagram for Users:
create_table "users", :force => true do |t|
t.string "first_name"
t.string "last_name"
t.text "reputation"
t.integer "questions_asked"
t.integer "answers_given"
t.string "request"
t.datetime "created_at"
t.datetime "updated_at"
t.string "email_hash"
t.string "username"
t.string "hashed_password"
t.string "salt"
end
User personal information (username, first and last name, email address) is filled in through POST. Other applications, such as questions_asked, reputationetc., are installed by the application, so they must be initialized when creating new users. Right now, I'm just setting each of them manually in a method createfor UsersController:
def create
@user = User.new(params[:user])
@user.reputation = 0
@user.questions_asked = 0
@user.answers_given = 0
@user.request = nil
...
end
Is there a more elegant / efficient way to do this?
source
share