azback5
Joined 10/27/2020
azback5 said about 4 years ago on User Notifications :
Ah, create CommentNotifier method in Comment model you mean? If so, I'm just wondering how you would define it.

Thanks David!

azback5 said about 4 years ago on User Notifications :
I've placed it in my Comment model and here is how I've tried to define it so far, but I doubt that it makes sense..

In my Comment model ...
  def CommentNotifier
      if self = @commentable
      else 
        nil
      end
    end




azback5 said about 4 years ago on User Notifications :
  Thanks, so I just implemented this in a CommentNotifier model as you've written (correcting the typo above in your def self.call at the beginning 'comnet' to 'comment' and here is how the create method looks in my Comments Controller...

  def create

      @comment = @commentable.comments.new(comment_params)
      @comment.user = @current_user
      if @comment.save
        CommentNotifier.call(comment, current_user)
        respond_to do |format|
          format.html { redirect_to @commentable }
          format.js # create.js.erb
        end
      else
        redirect_to cookies[:original_referrer]
        flash[:error] = "Comment could not be created."
      end
    end

But I receive this error 

NameError (undefined local variable or method `comment' for #<BlogPosts::CommentsController:0x00007fd7bfe4c818>
Did you mean?  @comment):
  
app/controllers/comments_controller.rb:18:in `create'

which is puzzling because it seems to point to my namespaced BlogPosts::CommentsController < CommentsController

class BlogPosts::CommentsController < CommentsController

    before_action :set_commentable

    def new
     @comment = Comment.new(commentable: @commentable)
   end


  private

  def set_commentable
    @commentable = BlogPost.friendly.find(params[:blog_post_id])
  end
end

I'll be happy to send you a link to my GitHub repo if that will help provide more insight!

Thanks for your time and consideration...


azback5 said about 4 years ago on User Notifications :
  do you mean @comment here in my Comments Controller create action?

CommentNotifier.call(@comment, @current_user)

If I enter this then I get this error...

ArgumentError (wrong number of arguments (given 1, expected 2)):
  
app/models/comment_notifier.rb:12:in `initialize'
app/models/comment_notifier.rb:5:in `call'
app/controllers/comments_controller.rb:18:in `create'



azback5 said about 4 years ago on User Notifications :
  Why would it be only accepting one argument?