Tag: json api

Active Model Serializer和Pundit在显示CRUD操作期间删除记录

好的,这里有些东西被严重破坏了…… 我正在为我的Rails 5 JSONAPI服务器使用Active Model Serializer和Pundit,为我的前端应用程序使用Ember。 我有User模型和User模型的Pundit策略,可以防止非作者查看未发表的故事和章节。 目前,我看到一个奇怪的问题,如下所示: 1. UserA creates StoryA, and two published chapters Chapter1 and Chapter2 2. UserA then creates two unpublished chapters Chapter3 and Chapter4 3. UserA logouts 4. UserB logins 5. UserB views the same story created by UserA 6. Server policy kicks in and scope the results to only […]

使用active_model_serializers序列化模型数组

我试图使用gem active_model_serializers将模型的序列化版本作为参数发送到视图 #app/serializers/admin_serializer.rb class AdminSerializer true).page(params[:page]).per(10) @page_entries_info = view_context.page_entries_info @admins # render json: @admins respond_to do |format| format.html format.js format.json {render json: @admins} end end #app/views/dashboard/admins/index.html.erb 以上调试产生以下响应: — ‘{“data”:{“id”:”1″,”type”:”admins”,”attributes”:{“email”:”tech@bluesapling.com”,”access_locked?”:false}}}’ //returned by the first debug — – ‘{“object”:{“id”:36,”email”:”aubrey_schmitt@feeneykoch.io”,”created_at”:”2016-03-28T05:15:17.546Z”,”updated_at”:”2016-03-28T05:15:17.546Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:20,”email”:”alysa_johnston@thompson.io”,”created_at”:”2016-03-28T05:15:16.304Z”,”updated_at”:”2016-03-28T05:15:16.304Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:22,”email”:”kristofer.langosh@kunzeluettgen.com”,”created_at”:”2016-03-28T05:15:16.459Z”,”updated_at”:”2016-03-28T05:15:16.459Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:37,”email”:”beryl_keler@wiza.biz”,”created_at”:”2016-03-28T05:15:17.624Z”,”updated_at”:”2016-03-28T05:15:17.624Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:5,”email”:”wilhelmine_buckridge@crona.io”,”created_at”:”2016-03-28T05:15:15.139Z”,”updated_at”:”2016-03-28T05:15:15.139Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:14,”email”:”edward_wisoky@corkery.net”,”created_at”:”2016-03-28T05:15:15.838Z”,”updated_at”:”2016-03-28T05:15:15.838Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:27,”email”:”leonor@jerde.biz”,”created_at”:”2016-03-28T05:15:16.848Z”,”updated_at”:”2016-03-28T05:15:16.848Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:2,”email”:”carley@wyman.net”,”created_at”:”2016-03-28T05:15:14.873Z”,”updated_at”:”2016-03-28T05:15:14.873Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:10,”email”:”ervin.gleichner@cremin.org”,”created_at”:”2016-03-28T05:15:15.527Z”,”updated_at”:”2016-03-28T05:15:15.527Z”},”instance_options”:{},”root”:null,”scope”:null}’ – ‘{“object”:{“id”:15,”email”:”lonzo.dickens@johnscole.name”,”created_at”:”2016-03-28T05:15:15.916Z”,”updated_at”:”2016-03-28T05:15:15.916Z”},”instance_options”:{},”root”:null,”scope”:null}’ […]