Tag: 兔子

从rabl Rails调用Rails助手

我试图从我的rabl模板中调用Rails助手,但它不起作用。 我有一个图像对象,我想通过我的api传递它。 那么图像路径应该有完整的URL(例如: http:///uploads/myimage.jpg )。 我想通过Rails助手添加的主机部分。 #my rabl file object @image attributes :id, :picture_url 我想要的是(我尝试过但不起作用) #my rabl file object @image attributes :id, full_url(:picture_url) #app/helpers/application_helper.rb module ApplicationHelper def full_url(path) “#{request.host}#{path}” #something like this end end 但是当我这样做时,它会从json对象中完全删除:picture_url属性

在RABL模板中访问子实例

我有一个RABL模板,如下所示 object @user attributes :name child :contacts do # does not work if contact.is_foo? attributes :a1, :a2 else attributes :a3, :a4 end end 如何访问模板child块中的Contact对象? 我需要在子实例上执行一些条件逻辑。

删除RABL中的子根节点

我正在尝试使用RABL渲染一个非常简单的数据结构,但我无法弄清楚如何正确删除子根节点。 这是我的两个模板。 首先是集合索引模板。 collection @groups, :object_root => false attributes :id, :name child :files do extends ‘groups/_file’ end 接下来,文件部分模板。 object @file attributes :id 这两个模板最终生成以下JSON: [ { “id”:”4f57bf67f85544e620000001″, “name”:”Some Group”, “files”:[ { “file”:{ “id”:”4f5aa3fef855441009000007″ } } ] } ] 我想找到一种方法来删除文件集合中的根“文件”键。 就像是: [ { “id”:”4f57bf67f85544e620000001″, “name”:”Some Group”, “files”:[ { “id”:”4f5aa3fef855441009000007″ } ] } ]