Created
May 20, 2015 21:37
-
-
Save wtachau/be1cf1b3621732ef50e4 to your computer and use it in GitHub Desktop.
Return JSON instead of server-side rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CommentsController < ApplicationController | |
| include CommentsHelper | |
| def create | |
| @comment = (current_user.comments.create comments_params).decorate | |
| tagged_users = get_tagged_users(@comment) | |
| # render @comment | |
| # @current_post = Post.find(id: comments_params[:post_id]) | |
| @current_post = Post.first | |
| render json: @current_post.comments | |
| Thread.new do | |
| NotificationMailer.users_tagged(current_user, tagged_users, @comment).deliver_now | |
| NotificationMailer.commented_post(@comment).deliver_now | |
| end | |
| end | |
| private | |
| def comments_params | |
| params.require(:comment).permit(:post_id, :text, :image) | |
| end | |
| # Given the comment text, return list of user ids tagged | |
| def get_tagged_users(comment) | |
| ids = [] | |
| get_user_ids = lambda { |match| ids.push(userFromTag(match).email) } | |
| get_users_from(comment.text, get_user_ids) | |
| ids | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment