app/controllers/guts/users_controller.rb in guts-1.0.8 vs app/controllers/guts/users_controller.rb in guts-1.1.0

- old
+ new

@@ -1,6 +1,6 @@ -require_dependency "guts/application_controller" +require_dependency 'guts/application_controller' module Guts # Users controller class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :update, :destroy] @@ -8,11 +8,11 @@ # Displays a list of users # @note Filterable by group by passing `group` param def index if params[:group] @group = Group.find params[:group] - @users = User.includes(:groups).where(guts_groups: {id: @group.id}) + @users = User.in_group(@group) else @users = User.all end end @@ -33,31 +33,34 @@ # @note Redirects to #index if successfull or re-renders #new if not def create @user = User.new user_params if @user.save - redirect_to users_path, notice: "User was successfully created." + redirect_to users_path, notice: 'User was successfully created.' else render :new end end # Updates a user through patch # @note Redirects to #index if successfull or re-renders #edit if not def update if @user.update(user_params) - redirect_to users_path, notice: "User was successfully updated." + flash[:notice] = 'User was successfully updated.' + redirect_to users_path else render :edit end end # Destroys a single user # @note Redirects to #index on success def destroy @user.destroy - redirect_to users_url, notice: "User was successfully destroyed." + + flash[:notice] = 'User was successfully destroyed.' + redirect_to users_url end # Allows switching of users by passing `user_id` in params # @see Guts::SessionsHelper#log_in def switch_user @@ -69,19 +72,26 @@ @users = User.all end private + # Sets a user from the database using `id` param # @note This is a `before_action` callback # @private def set_user @user = User.find params[:id] end # Permits user params from forms # @private def user_params - params.require(:user).permit(:name, :email, :password, :password_confirmation, group_ids: []) + params.require(:user).permit( + :name, + :email, + :password, + :password_confirmation, + group_ids: [] + ) end end end