Ruby on rails rails中用于优化搜索的范围
我正在努力完善我的文章,让我的用户能够灵活地决定他们想看什么 这里是有关系的模型Ruby on rails rails中用于优化搜索的范围,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,我正在努力完善我的文章,让我的用户能够灵活地决定他们想看什么 这里是有关系的模型 Article has_many :tags, through: :articletags ArticleTags belongs_to :article belongs_to :tags Tags has_many :article, through: articletags 现在的想法是在文章中使用,并在侧面看到tags.title,然后使用article wher
Article
has_many :tags, through: :articletags
ArticleTags
belongs_to :article
belongs_to :tags
Tags
has_many :article, through: articletags
现在的想法是在文章中使用,并在侧面看到tags.title,然后使用article where tags=world刷新页面。现在我正试图用scope来做这件事,但我不知道该怎么做。这里是我的模型中的范围
scope :by_tags, where(title => ?, "world news")
这就是我的称呼
<%= link_to (tag.title), articles_path(:scope => "test") %>
但很明显,它不起作用。我如何修复它?查看
控制器
<%= link_to (tag.title), articles_path(:scope => tag.title) %>
def self.by_tags(tag)
joins(:tags).where('tags.title = ?', tag)
end
def index
@articles = Article.by_tags(params[:scope])
end