我有一个这样的对象:
irb(main):076:0> hints = Hint.where("sentence LIKE ?","%你%")
Hint Load (4.0ms) SELECT "hints".* FROM "hints" WHERE (sentence LIKE '%你%')
[
[0] #<Hint:0x007fb99c6520b8> {
:id => 214,
:sentence => "我为你们立下模范,我向你们怎样做,你们也该照样做。",
:user => nil,
:learned => nil,
:created_at => Sun, 06 Jan 2013 18:14:33 UTC +00:00,
:updated_at => Sun, 06 Jan 2013 18:14:33 UTC +00:00
},
[1] #<Hint:0x007fb99c659a70> {
:id => 229,
:sentence => "他快要完成地上的传道工作时,曾向耶和华祷告说“我已经使他们使徒认识你的名,以后还要使他们认识”。",
:user => nil,
:learned => nil,
:created_at => Sun, 06 Jan 2013 18:43:23 UTC +00:00,
:updated_at => Sun, 06 Jan 2013 18:43:23 UTC +00:00
},
[2] #<Hint:0x007fb99c659458> {
:id => 234,
:sentence => "你的王到你这里来了。",
:user => nil,
:learned => nil,
:created_at => Sun, 06 Jan 2013 18:48:12 UTC +00:00,
:updated_at => Sun, 06 Jan 2013 18:48:12 UTC +00:00
}
]
irb(main):077:0> hints.class
ActiveRecord::Relation < Object
如何按sentence
长度排序?
我的最终目标是,当有人在课程中点击一个汉字时,他们会看到一些最短的例句,作为对汉字含义的提示。
我正在使用 PostgreSQL。