skill-assessment-app/app/controllers/admin/user_controller.rb
Mark Moser 4bbd93ded1 rubocop noise: fixes FrozenStringLiteralComment
Adding the .ruby-verison file triggered previously un-run cops, specifically:

  This cop is designed to help upgrade to Ruby 3.0. It will add the
  comment `# frozen_string_literal: true` to the top of files to enable
  frozen string literals. Frozen string literals will be default in Ruby
  3.0. The comment will be added below a shebang and encoding comment. The
  frozen string literal comment is only valid in Ruby 2.3+.

More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
2016-09-08 10:30:13 -05:00

52 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Admin
class UserController < AdminController
def index
@users = User.order(:name)
end
def new
@user = User.new
end
def create
default_passwd = SecureRandom.urlsafe_base64(12)
@user = User.create({ password: default_passwd }.merge(user_params.to_h))
if @user.persisted?
UserMailer.welcome(@user, default_passwd).deliver_now
redirect_to admin_users_path, flash: { success: "Sucessfully created user #{@user.name}" }
else
flash[:error] = "Failed to save user."
render :new
end
end
def view
@user = User.find(params[:user_id])
end
def edit
@user = User.find(params[:user_id])
end
def update
@user = User.find(params[:user_id])
if @user.update_attributes(user_params)
redirect_to admin_user_path(@user.to_i),
flash: { success: "Sucessfully updated #{@user.name}" }
else
flash[:error] = "Failed to update user."
render :edit
end
end
private
def user_params
params.require(:user).permit(:name, :email, :role, :password)
end
end
end