所以,我有一个朋友帮助我让Omniauth-twitter工作。但是,现在我遇到了严重的问题。为了让Omniauth工作,我们必须将users表上的primary_key更改为:uid而不是:id。不知怎的,这影响了歌曲。
E.g。现在,当我搜索歌曲时,我收到以下错误:
ActiveRecord::RecordNotFound (Couldn't find all Songs with IDs (7, 9, 10, 18, 44, 46, 47, 55) (found 4 results, but was looking for 8)):
请让我知道我可以提供哪些代码来帮助解决此问题。
用户表(架构snippit)
create_table "users", id: false, force: true do |t|
t.integer "id", null: false
t.string "email", default: ""
t.string "encrypted_password", default: ""
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "admin"
t.string "provider"
t.string "uid", null: false
t.string "username"
end
答案 0 :(得分:3)
使用tire和elasticsearch时,请确保更新elasticsearch的索引,以便它不会返回错误的ID或缺少您删除的记录ID。如果要删除歌曲,可以考虑如何更新索引。
rake environment tire:import CLASS=Song FORCE=true
在你可以添加的歌曲的破坏行动中:
system "rake environment tire:import CLASS=Song FORCE=true"
更新歌曲索引。
def destroy
@song.destroy
system "rake environment tire:import CLASS=Song FORCE=true"
respond_to do |format|
format.html { redirect_to songs_url }
format.json { head :no_content }
end
end
凯文评论后更新
Song.tire.index.remove @song #this will remove loaded song from index
方法destroy现在应该如下所示:
def destroy
Song.tire.index.remove @song
@song.destroy
respond_to do |format|
format.html { redirect_to songs_url }
format.json { head :no_content }
end
end
在这里找到答案:https://github.com/karmi/tire
方法Tire::Index#store
和Tire::Index#remove