0

我想从 2 个设备中获取 2 个 url 图像。我的模型结构:

比较: has_one :device1, has_one :device2

设备: has_one :image

图片:mount_uploader:图片,ImageUploader

在查询中,我想从查询中获取 JSON 数组比较

@compares = Compare.any_of({:device1_id.in => arr_device_id},{:device2_id.in => arr_device_id})

我试试:(标题是 attr_accessor)

Compare.any_of({:device1_id.in => arr_device_id},{:device2_id.in => arr_device_id}).only(:title => 'abc'). Result json is not contain field title


@compare.to_json(:include => [:device1,:device2]) => this include device1 and device2 but not include image of it.


@compare.to_json(:method => [:title => 'abc'])   . Result json is not contain field title

有什么解决办法吗?感谢您的帮助:D

4

1 回答 1

0

您的意思only(:title => "abc")是只选择字段“标题”吗?

然后,解决方案可能会用 only(:title) 替换它

如果你的意思只是标题是“abc”,那么替换only(:title => "abc")where(:title => "abc")

to_json 应该可以工作。

于 2013-08-25T13:45:32.600 回答