Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app/services/add_comment_to_post.rb
- class AddCommentToPost
- def initialize(post:, comment:)
- @post = post
- @comment = comment
- end
- def call
- @post.comments.create(@comment)
- @post
- end
- end
- app/services/remove_comment_from_class.rb
- class RemoveCommentFromPost
- def initialize(post:, comment:)
- @post = post
- @comment = comment
- end
- def call
- @post.comments.@comment.id.destroy
- @post
- end
- end
- def create
- #this one works:
- #@post.comments.create! comment_params
- AddCommentToPost.new(@post, @comment).call
- redirect_to @post
- def destroy
- RemoveCommentFromPost.new(@post,@comment).call
- redirect_to @post
- Rails.application.routes.draw do
- resources :posts do
- resources :comments
- end
- root "posts#index"
- end
- def initialize(post:, comment:)
- @post = post
- @comment = comment
- end
- AddCommentToPost.new(@post, @comment).call
- AddCommentToPost.new(post: @post, comment: @comment).call
- def destroy
- RemoveCommentFromPost.new(@post,@comment).call
- redirect_to @post
Add Comment
Please, Sign In to add comment