Skip to content

Instantly share code, notes, and snippets.

@3den
Created November 30, 2017 22:23

Revisions

  1. 3den revised this gist Nov 30, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion bad_controller.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    #What’s wrongthe issue with the controller code below? How would you fix/improve it?
    #What’s the issue with the controller code below? How would you fix/improve it?

    class CommentsController < ApplicationController
    ...

    def users_comments
    posts = Post.all
    comments = posts.map(&:comments).flatten
  2. 3den created this gist Nov 30, 2017.
    11 changes: 11 additions & 0 deletions bad_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #What’s wrongthe issue with the controller code below? How would you fix/improve it?

    class CommentsController < ApplicationController
    def users_comments
    posts = Post.all
    comments = posts.map(&:comments).flatten
    @user_comments = comments.select do |comment|
    comment.author.username == params[:username]
    end
    end
    end