guoren/app/controllers/users_controller.rb

40 lines
623 B
Ruby
Raw Normal View History

2016-12-22 20:00:08 +08:00
class UsersController < ApplicationController
def new
@user = User.new
end
2016-12-26 11:00:51 +08:00
2016-12-22 20:00:08 +08:00
def create
@user = User.new(user_params)
if @user.save
log_in @user
redirect_to main_path
else
render 'new'
end
end
2016-12-22 20:05:38 +08:00
def edit
@user = current_user
render 'edit'
end
2016-12-25 16:44:43 +08:00
def update
if @user.update_attributes(user_params)
flash[:success]="profile updated"
redirect_to @user
else
render 'edit'
end
end
2016-12-22 20:00:08 +08:00
private
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
end
2016-12-22 20:05:38 +08:00
2016-12-22 20:00:08 +08:00
end