2017-12-29 194 views
0

私はAPIを使って学生を登録しようとしています。私は郵便配達員を使ってテストしています。私はハッシュでActiveModel :: Serializer :: Null ::のこの問題を解決するには

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) 

そして、ここに新しい学生を投稿しようとしたときにここに私のコントローラである私のログです:

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 
+1

を@jungleManフィールそれがあなたを助けたらnswerを受け入れるか自由にupvoteしてください。 – Gabbar

答えて

1

この

BaseController変更: -

before_action :authenticate_user!, except: [:new] 
関連する問題