使用json输出:
{
"Functions":[
{
"CodeSha256":"7NBvXXacp9x3aK3cKaI=",
"FunctionName":"function_1",
"FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_1",
"LastModified":"2015-02-09T11:35:31.084+0000"
},
{
"CodeSha256":"7NBvXXacKaI=",
"FunctionName":"function_3",
"FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_3",
"LastModified":"2015-03-09T11:35:31.084+0000"
},
{
"CodeSha256":"7NBvXXacaK3cKaI=",
"FunctionName":"function_2",
"FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_2",
"LastModified":"2015-02-11T11:35:31.084+0000"
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何返回按LastModified排序的两个最新函数?
我想预加载关联,但如果不存在关联,我想返回主要关系。
要理解我的问题,这里有一个可重现的脚本:
# frozen_string_literal: true
gem 'rails'
require 'active_record'
puts "Active Record #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: ':memory:'
)
ActiveRecord::Schema.define do
create_table :organisations, force: true do |t|
t.string 'name', limit: 255, null: false
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table :groups, force: true do |t|
t.string 'name', limit: 255, null: false
t.integer 'shop_id', null: false
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table :groups_organisations, force: true do |t|
t.integer 'organisation_id', null: false
t.integer 'group_id', null: false
t.datetime 'created_at'
t.datetime 'updated_at'
end
end
class …Run Code Online (Sandbox Code Playgroud) 我在Rails项目中使用了jbuilder。
在路线上,我可以获取设备的索引或显示带有其ID的设备。
但是用户有很多设备。因此,在此路线上,users/:id/devices我希望能够获得设备。目前,我_device.json.jbuilder对路径有部分的称呼app/views/api/v1/devices/_device.json.jbuilder。我想打电话给app/views/api/v1/users/devices.json.jbuilder