【发布时间】:2014-01-03 14:14:24
【问题描述】:
如何使用 Ruby Gem ActiveRecord、Sinatra 和 Postgres 进行单词搜索?
我的桌子是这样的:
create_table "posts", :force => true do |t|
t.string "title"
t.text "body"
t.string "image_url"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
我正在尝试在标题和正文字段中搜索关键词。
使用ActiveRecord Documentation,我尝试了Post.find_by(body: "a"),但得到了一个空结果,其中我的身体确实包含字符a
我知道在 Rails 中你会这样做:
Post.where(["body LIKE :tag", {:tag => word}])
但我不知道如何使用 Sinatra 和 Postgres 来做同样的事情。
【问题讨论】:
-
到目前为止你的尝试是什么形式?请发布代码,即使它不完整,并显示您卡在哪里。这样可以更好地了解如何最好地帮助您。
-
@NeilSlater 我更新了我的问题。希望它显示了我所做的尝试。
标签: sql ruby postgresql activerecord sinatra