Sha256: 1055ef2dfd3e41389cd9837bca32df57df3a1e5a91e339ed2a8b7cca75c553c3

Contents?: true

Size: 1007 Bytes

Versions: 7

Compression:

Stored size: 1007 Bytes

Contents

module Ecom
  module Core
    class UserRolesController < ApplicationController
      before_action :set_user_role, only: [:update]

      def index
        render json: UserRoleSerializer.new(UserRole.all)
      end

      def create
        user_role = UserRole.new(user_role_params)

        if user_role.save
          render json: UserRoleSerializer.new(user_role), status: :created
        else
          render json: { success: false, errors: user_role.errors }, status: :unprocessable_entity
        end
      end

      def update
        if @user_role.update(user_role_params)
          render json: UserRoleSerializer.new(@user_role)
        else
          render json: { success: false, errors: @user_role.errors }, status: :unprocessable_entity
        end
      end


      private

      def set_user_role
        @user_role = UserRole.find(params[:id])
      end

      def user_role_params
        params.require(:user_role).permit(:name, :application_module_id)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ecom_core-1.1.2 app/controllers/ecom/core/user_roles_controller.rb
ecom_core-1.1.1 app/controllers/ecom/core/user_roles_controller.rb
ecom_core-1.1.0 app/controllers/ecom/core/user_roles_controller.rb
ecom_core-1.0.25 app/controllers/ecom/core/user_roles_controller.rb
ecom_core-1.0.24 app/controllers/ecom/core/user_roles_controller.rb
ecom_core-1.0.23 app/controllers/ecom/core/user_roles_controller.rb
ecom_core-1.0.22 app/controllers/ecom/core/user_roles_controller.rb