思考狮身人面像和范围的问题

发布于 2024-10-04 18:18:22 字数 763 浏览 3 评论 0原文

几个小时以来,我一直在尝试让狮身人面像瞄准镜正常工作,但没有成功。

我想确定 ActsAsTaggableOn 标签的范围。在我的模型(可标记)中,我尝试了以下范围:

# This normal scope works
scope :tagged, lambda {
  joins(:taggings => :tag).
  where("tags.name = 'consequatur'")
}

# fails! (can't convert ActiveRecord::Relation into Hash)
sphinx_scope :tagged do
  joins(:taggings => :tag).
  where("tags.name = 'consequatur'")
end

使用旧条件的另一次尝试:

# works with normal scope (returns one record)
scope :tagged, :joins => :taggings, :conditions => {"taggings.tag_id" => 74}

# fails! (returns nothing)
sphinx_scope(:tagged) do
  {:joins => :taggings, :conditions => {"taggings.tag_id" => 74}}
end

如何使这些范围起作用?还有其他方法可以存档该任务吗?我只想搜索那些标有特定标签的模型。

For several hours now I am unsuccessfully trying to get sphinx scopes work.

I want to scope tags of ActsAsTaggableOn. In my model (that is taggable) I tried the following scopes:

# This normal scope works
scope :tagged, lambda {
  joins(:taggings => :tag).
  where("tags.name = 'consequatur'")
}

# fails! (can't convert ActiveRecord::Relation into Hash)
sphinx_scope :tagged do
  joins(:taggings => :tag).
  where("tags.name = 'consequatur'")
end

Another try with the old conditions:

# works with normal scope (returns one record)
scope :tagged, :joins => :taggings, :conditions => {"taggings.tag_id" => 74}

# fails! (returns nothing)
sphinx_scope(:tagged) do
  {:joins => :taggings, :conditions => {"taggings.tag_id" => 74}}
end

How can I make those scopes work? Is there another way to archive that task? I want to only search those models that are tagged with a specific tag.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文