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
Reply
Join the discussion
Create an account Log in

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.