Sha256: f06909b2ea0d6dd4ec3593d362c43b60e1fda762faee28a61fb76937c2afde02

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

require_dependency 'cavy/application_controller'

module Cavy
  class UsersController < ApplicationController

    before_action :set_user, only: [:show, :edit, :update]
    layout 'cavy/admin_layout'

    def index
      @users = User.all
    end

    def show
    end

    def new
      @user = User.new
    end

    def edit
    end

    def create
      @user = User.new(user_params)

      if @user.save
        redirect_to @user, notice: 'User was successfully created.'
      else
        render action: 'new'
      end
    end

    def update
      if @user.update_attributes(user_params)
        redirect_to @user, notice: 'User was successfully updated.'
      else
        render action: 'edit'
      end
    end

    private

    def set_user
      @user = User.find(params[:id])
    end

    def user_params
      @role = params[:user][:role]
      params.require(:user).permit(:email, :password, :password_confirmation, :name, :role)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cavy-0.1.0.beta1 app/controllers/cavy/users_controller.rb