0
私はRails 5アプリでactive_model_serializers
gemを使用しています。 /app/seralizers
、user_serializer.rb
、sector_serializer.rb
、およびslot_serializer.rb
にいくつかのシリアライザファイルを作成しました。Rails NoMethodError:#<ユーザ:0x007f62dbbe62f8>のための未定義メソッド `includes '
class UserSerializer < ActiveModel::Serializer
attributes :id, :first_name, :last_name, :email, :phone, :admin, :auth_token, :organization_id
has_many :sectors
has_many :slots
has_many :elements
end
class SectorSerializer < ActiveModel::Serializer
attributes :id, :user_id, :sector_number, :title
belongs_to :user
has_many :slots
has_many :elements
end
class SlotSerializer < ActiveModel::Serializer
attributes :id, :user_id, :sector_id, :sector_number, :title, :slot_number
belongs_to :user
belongs_to :sector
has_many :elements
end
そして、私のコントローラのコードでは、私が持っている:
class Api::V1::UsersController < API::V1::BaseController
respond_to :json
def sky
@user = User.find_by_id(params[:user_id]).includes(:sectors, :slots)
if @user
render json: @user
else
raise "Unable to get Sky"
end
end
end
私のサーバーは、私は.includes
を行うと、私はその理由を把握することはできません行でエラーを投げています。
何か助けていただければ幸いです。ありがとう!
パーフェクト。本当にありがとうUrsus –
私の喜びSir :) – Ursus