Guest User

Untitled

a guest
May 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. def add_comment(id)
  2. @post = Post.get(id)
  3. raise NotFound unless @post
  4.  
  5. #@comment = @post.comments.build(params) #=> Does not work
  6. # Something I was playing with that works
  7. props = Comment.properties.map {|p| p.name}
  8. c_params = params.select {|k,v| props.include?(k.to_sym) unless k == 'id'}
  9. @comment = @post.comments.build(c_params)
  10. =begin
  11. @comment = @post.comments.build( # ugly but it works
  12. :posted_by => params[:posted_by],
  13. :email => params[:email],
  14. :body => params[:body]
  15. ## Other params here
  16. )
  17. =end
  18. if @comment.save
  19. message[:message] = "Comment Created"
  20. else
  21. message[:error] = "Comment failed to be created"
  22. end
  23. redirect resource(@post)
  24. end
Add Comment
Please, Sign In to add comment