は、私は単純なモデルがあります:アクティブなモデルシリアライザrespond_withが未定義のメソッド "to_model"を引き起こしますか?
class Receipt
include ActiveModel::Serialization
attr_accessor :products
end
を、私のコントローラがやっている:
def create
respond_with receipt, :serializer => ReceiptSerializer
end
とシリアライザ:
class ReceiptSerializer < ActiveModel::Serializer
attributes :products
end
をし、私が取得:
NoMethodError: undefined method `to_model' for #<Receipt:0x007f99bcb3b6d8>
しかし、私は私のコントローラを変更した場合:
def create
json = ReceiptSerializer.new(receipt)
render :json => json
end
その後、すべてが何が起きているのか...正常に動作します?
私はactive_model_serializers 0.9.3を使用していましたが、0.10.2を試したところ、結果は同じです。
ああ、私はrespond_withがActiveModelSerializersを使用する適切な方法だと思いましたか?それは変わったのですか? – patrick
Railsを6年間使用したことはありません。しかし、それは一度にそれを行う適切な方法ではなかったことを意味しません。 https://github.com/rails-api/active_model_serializers/blob/master/docs/general/rendering.md – Genzume
respond_withをgemに移動しました:https://stackoverflow.com/questions/25998437/why-is-respond-レールを取り外した状態で - 4-2 - 自社製の宝石 –