learningrails

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

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