Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 4中使用acts_as_taggable_创建的主题(标记)_Ruby On Rails_Ruby On Rails 4_Acts As Taggable On - Fatal编程技术网

Ruby on rails 我希望用户能够关注在Rails 4中使用acts_as_taggable_创建的主题(标记)

Ruby on rails 我希望用户能够关注在Rails 4中使用acts_as_taggable_创建的主题(标记),ruby-on-rails,ruby-on-rails-4,acts-as-taggable-on,Ruby On Rails,Ruby On Rails 4,Acts As Taggable On,我有一个很像stackoverflow的问题模型 用户可以添加问题。在问题表格中有:标题、主题、地点、描述 每个主题都有自己的显示页面,其中包含包含该主题的问题提要 我想添加一个功能,这样当用户在主题的“显示”页面上时,就会有一个“跟随”按钮,用户将能够跟随主题 我不确定acts__as_taggable是否有内置的功能来执行此操作?我使用acts_作为_跟随者,这样用户可以互相跟随,这一切都很好 我打算尝试在主题上使用acts_作为跟随者,但我不知道如何使用,因为没有通过acts_as_tag

我有一个很像stackoverflow的问题模型

用户可以添加问题。在问题表格中有:标题、主题、地点、描述

每个主题都有自己的显示页面,其中包含包含该主题的问题提要

我想添加一个功能,这样当用户在主题的“显示”页面上时,就会有一个“跟随”按钮,用户将能够跟随主题

我不确定acts__as_taggable是否有内置的功能来执行此操作?我使用acts_作为_跟随者,这样用户可以互相跟随,这一切都很好

我打算尝试在主题上使用acts_作为跟随者,但我不知道如何使用,因为没有通过acts_as_taggable_创建的“主题”模型

主题_controller.rb用于显示页面

class TopicController < ApplicationController
  def index
    @questions = Question.tagged_with(params[:topic])

      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @questions }
      end
  end
end
class-TopicController
任何想法和代码都会很有帮助


谢谢

您可以创建一个继承自ActsAsTaggableOn::Tag的主题模型,并将acts_添加到该模型中

# app/models/topic.rb
class Topic < ActsAsTaggableOn::Tag
  acts_as_followable
end
#app/models/topic.rb
类主题
然后,您可以使用topic作为标记:

# app/models/post.rb
class Post < ActiveRecord::Base
  acts_as_taggable_on :topics
end
#app/models/post.rb
类Post