jungleMan
jungleMan

Reputation: 888

How do I solve this issue of ActiveModel::Serializer::Null::with Hash

I am trying to register a student using the API. I am using postman to test. Here are my logs whenever I try to post a new student

Started POST "/api/v1/students/" for 127.0.0.1 at 2017-12-29 12:11:12 -0500
Processing by Api::V1::StudentsController#create as */*
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash 
(0.12ms)
Filter chain halted as :authenticate_user! rendered or redirected
Completed 401 Unauthorized in 3ms (Views: 1.1ms | ActiveRecord: 0.0ms)

Started POST "/api/v1/students/" for 127.0.0.1 at 2017-12-29 12:14:07 -0500
Processing by Api::V1::StudentsController#create as */*
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash 
(0.19ms)
Filter chain halted as :authenticate_user! rendered or redirected
Completed 401 Unauthorized in 106ms (Views: 103.7ms | ActiveRecord: 0.0ms)

And here is my controller:

class Api::V1::StudentsController < Api::V1::BaseController

    def create
        student = Student.new(student_params)

        if student.save
            render json: {status: 'SUCCESS', message: 'Registered', data: student_data}, status: :ok
        else
            render json: {status: 'ERROR', message: 'Student not registered', data: student.errors}, status: :unprocessable_entity
        end 
    end

end

Upvotes: 0

Views: 2109

Answers (1)

Anand
Anand

Reputation: 6531

modify this

BaseController: -

before_action :authenticate_user!, except: [:new]

Upvotes: 2

Related Questions