Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在没有葡萄api的情况下使用葡萄实体?_Ruby On Rails_Grape_Grape Api - Fatal编程技术网

Ruby on rails 如何在没有葡萄api的情况下使用葡萄实体?

Ruby on rails 如何在没有葡萄api的情况下使用葡萄实体?,ruby-on-rails,grape,grape-api,Ruby On Rails,Grape,Grape Api,我正在尝试使用没有GrapeAPI gem的GrapeEntity。因此,只需将其用作原始rails控制器的序列化程序 尝试通过执行以下操作来展示我的资源时: present User.all,with:Entities::User 我发现present方法未定义 我应该如何使用实体表示这些资源?文档中说要使用present我还需要在Grape之外使用Grape实体(在基本Rails控制器中),最后我使用了Chris建议: 实体::MyResource.representation MyReso

我正在尝试使用没有GrapeAPI gem的GrapeEntity。因此,只需将其用作原始rails控制器的序列化程序

尝试通过执行以下操作来展示我的资源时:

present User.all,with:Entities::User

我发现
present
方法未定义


我应该如何使用实体表示这些资源?文档中说要使用
present

我还需要在Grape之外使用Grape实体(在基本Rails控制器中),最后我使用了Chris建议:

实体::MyResource.representation MyResource.first


它很有魅力,谢谢

您能否尝试
实体::User.representation User.all
?附加提示:一旦您拥有表示对象的实体实例,您就可以在其上调用
可序列化的_散列