I want a user to be able to follow a topic(tag) that is created with acts_as_taggable_on in Rails 4
Asked Answered
P

1

9

I have a question model much like stackoverflow.

A user can add a question. In the question form there is :Title, :topics, :place, :description

Each topic has its own show page which has a feed of questions that contain the topic.

I want to add a feature so that when a user is on the show page of the topic there is a follow button and the user will be able to follow the topic.

I'm not sure if acts_as_taggable has an in built feature to do so? I am using acts_as_follower so users can follow each other and this is all working fine!

I was going to try to use acts_as_follower on the topics but I have no idea how since there is no 'topic' model as it is created via acts_as_taggable_on

topic_controller.rb for show page

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

Any ideas and code will help alot,

Thanks!

Pacian answered 15/1, 2014 at 12:53 Comment(0)
D
1

You can create a Topic model that inherits from ActsAsTaggableOn::Tag, and add acts_as_followable to that model.

# app/models/topic.rb
class Topic < ActsAsTaggableOn::Tag
  acts_as_followable
end

Then, you can use topic as your tag:

# app/models/post.rb
class Post < ActiveRecord::Base
  acts_as_taggable_on :topics
end
Deuce answered 18/1, 2016 at 6:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.