Class: Ecom::Core::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ecom/core/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #logged_in?

Instance Method Details

#activeObject



15
16
17
# File 'app/controllers/ecom/core/users_controller.rb', line 15

def active
  render json: User.active
end

#createObject



19
20
21
22
23
24
25
26
# File 'app/controllers/ecom/core/users_controller.rb', line 19

def create
  user = User.new(user_params)
  if user.save
    render json: user, status: :created
  else
    render json: { success: false, errors: user.errors }, status: :unprocessable_entity
  end
end

#indexObject



6
7
8
# File 'app/controllers/ecom/core/users_controller.rb', line 6

def index
  render json: User.all
end

#lookupObject



10
11
12
13
# File 'app/controllers/ecom/core/users_controller.rb', line 10

def lookup
  data = ActiveModelSerializers::SerializableResource.new(User.all, each_serializer: UserLookupSerializer)
  render json: { success: true, data: data }
end

#updateObject



28
29
30
31
32
33
34
# File 'app/controllers/ecom/core/users_controller.rb', line 28

def update
  if @user.update(user_params)
    render json: @user
  else
    render json: { success: false, errors: @user.errors }, status: :unprocessable_entity
  end
end