Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_comment(id)
- @post = Post.get(id)
- raise NotFound unless @post
- #@comment = @post.comments.build(params) #=> Does not work
- # Something I was playing with that works
- props = Comment.properties.map {|p| p.name}
- c_params = params.select {|k,v| props.include?(k.to_sym) unless k == 'id'}
- @comment = @post.comments.build(c_params)
- =begin
- @comment = @post.comments.build( # ugly but it works
- :posted_by => params[:posted_by],
- :email => params[:email],
- :body => params[:body]
- ## Other params here
- )
- =end
- if @comment.save
- message[:message] = "Comment Created"
- else
- message[:error] = "Comment failed to be created"
- end
- redirect resource(@post)
- end
Add Comment
Please, Sign In to add comment