active-model-serializers

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

孤人 提交于 2021-01-02 05:55:42
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

陌路散爱 提交于 2021-01-02 05:55:21
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

自作多情 提交于 2021-01-02 05:55:14
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

Work around for issue multiple user models with devise_token_auth and active_model_serializers?

自闭症网瘾萝莉.ら 提交于 2020-02-05 04:08:13
问题 The combination of multiple user models (User, Admin, and Master) with devise_token_auth does not successfully set the Response Headers (uid, token, etc.) upon login with non "User" models (Admin and Master); however, User model works. The cause looks to be the default serialization_scope (:current_user) in active_model_serializers/lib/action_controller/serialization.rb:18. Is there a way to set the serialization_scope, or do I need to override the controllers? Environment: Rails 4.2.6 AMS 10

Use active_model_serializer with a non-ActiveRecord object

我们两清 提交于 2020-01-22 08:19:25
问题 I have a model object that is not descended from ActiveRecord::Base and is not stored in the database. I created a serializer for it (with the same name + "Serializer"), and in my controller I'm calling render json: object_instance . The result is an exception from deep inside of render . I implemented an as_json method that instantiates the serializer and calls it, but the result is then a missing method in the object, read_attribute_for_serialization . I want my object to act like an

ActiveModel::Serializer not working

末鹿安然 提交于 2020-01-17 08:25:09
问题 I have a Client model and a method in my controller that should return the nearest clients. I'm using ActiveModel::Serializers but it's not working. class ClientSerializer < ActiveModel::Serializer attributes :id, :name, :path, :url def url client_url(object) end def path client_path(object) end end controller: def nearby_from_category @closest_clients = Client.from_category(params[:category]). activated.locateable.all_with_translation(@lang). by_distance(origin: remote_ip).limit(2) render

rails ams, Nested models undefined method `' for nil:NilClass

对着背影说爱祢 提交于 2020-01-17 05:46:46
问题 I have the following models: class Appeal < ActiveRecord::Base belongs_to :applicant, :autosave => true belongs_to :appealer, :autosave => true end class Appealer < ActiveRecord::Base has_many :appeals, :autosave => true end class Applicant < ActiveRecord::Base has_many :appeals end What I want is for every appealer to hold a reference to the applicant of his last appeal so I modified Appealer model to: class Appealer < ActiveRecord::Base has_many :appeals, :autosave => true def last

Expected format for validation errors in Ember Data (using ActiveModel::Serializers)

≯℡__Kan透↙ 提交于 2020-01-16 19:14:29
问题 Unfortunately, ActiveModel::Serializers does not currently support validation errors, though they're scheduled for 1.0. Until then, I've got to hack a solution of my own. The big problem? I have no idea what format Ember Data's ActiveModelAdapter expects these errors to be in. I tried simply passing in the errors property, but Ember Data didn't pick up on it: class MySerializer < ActiveModel::Serializer attributes :errors end So what should I pass in instead? 回答1: I use this method to render