All threads / how can i to combine acts_as_commentable_with_threading and notification system ?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

how can i to combine acts_as_commentable_with_threading and notification system ?

learningrails asked in Rails

i got undefined method `users' for #Comment:0x007fb91b018818 Did you mean? user user=

comments_controller

def create
    commentable = commentable_type.constantize.find(params["comment"]["commentable_id"])
    @comment = Comment.build_from(commentable, current_user.id, body)

    respond_to do |format|
      if @comment.save


        (@comment.users.uniq - [current_user]).each do |user|
          Notification.create(repient: user, actor: current_user, action: "posted", notifiable: @comment)
        end

        @comment.create_activity :create, owner: current_user
        make_child_comment
        format.html  { redirect_to(:back, :notice => 'Comment was successfully added.') }
      else
        format.html  { render :action => "new" }
      end
    end
  end

routes.rb

resources :forums, only: [:index, :show] do
    resources :posts, only: [:new, :create]
  end

    resources :comments, only: [:create, :destroy, :update] do
    resources :likes, only: [:create, :destroy]
  end

post.rb

class Post < ApplicationRecord
  belongs_to :user
  belongs_to :forum
  has_many :clips, dependent: :destroy
  has_many :users, through: :clip
  has_many :comments
  has_many :users, through: :comments
  acts_as_commentable
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.