Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails中用于优化搜索的范围_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 3.1 - Fatal编程技术网

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