{"action":"created","comment":{"url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/comments/25784311","id":25784311,"diff_hunk":"@@ -13,76 +11,27 @@ def generate!(&block)\n \n           #INDEX\n           get \"/#{route}/?\" do\n-            unless params[:sort].blank?\n-              if params[:asc] == 'false'\n-                @collection ||= model.all.desc(params[:sort])\n-              else\n-                @collection ||= model.all.asc(params[:sort])\n-              end\n-            else\n-              @collection ||= model.all\n-            end\n-            @collection = @collection.page(params[:page] || 1)\n-\n+            sort_attr, sort_by = params[:sort].blank? ? %w(created_at desc) : params[:sort].split(\" \")\n+            @collection = model.send(sort_by, sort_attr).page(params[:page] || 1)\n             haml :index, format: :html5\n           end\n \n           #EXPORT ALL\n           get \"/#{route}/export/all/?\" do\n-            unless params[:sort].blank?\n-              if params[:asc] == 'false'\n-                @collection ||= model.all.desc(params[:sort])\n-              else\n-                @collection ||= model.all.asc(params[:sort])\n-              end\n-            else\n-              @collection ||= model.all\n-            end\n-\n+            sort_attr, sort_by = params[:sort].blank? ? %w(created_at desc) : params[:sort].split(\" \")\n+            @collection = model.send(sort_by, sort_attr)\n             content_type 'application/csv'\n             attachment \"#{route}-all-#{Date.today.to_s}.csv\"\n-\n-            CSV.generate do |csv|\n-              csv << model.attribute_names\n-              \n-              @collection.each do |item|\n-                row = []\n-                model.attribute_names.each do |col|\n-                  row << item[col]\n-                end\n-                csv << row\n-              end\n-            end\n+            Presenters::CsvGenerator.new(@collection, model.attribute_names).export_csv","path":"lib/sinatra-admin/register/model.rb","position":54,"original_position":54,"commit_id":"1d99487bd23f2ec712f525859d9c7224719c37f1","original_commit_id":"1d99487bd23f2ec712f525859d9c7224719c37f1","user":{"login":"franciscodelgadodev","id":3377694,"avatar_url":"https://avatars.githubusercontent.com/u/3377694?v=3","gravatar_id":"","url":"https://api.github.com/users/franciscodelgadodev","html_url":"https://github.com/franciscodelgadodev","followers_url":"https://api.github.com/users/franciscodelgadodev/followers","following_url":"https://api.github.com/users/franciscodelgadodev/following{/other_user}","gists_url":"https://api.github.com/users/franciscodelgadodev/gists{/gist_id}","starred_url":"https://api.github.com/users/franciscodelgadodev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/franciscodelgadodev/subscriptions","organizations_url":"https://api.github.com/users/franciscodelgadodev/orgs","repos_url":"https://api.github.com/users/franciscodelgadodev/repos","events_url":"https://api.github.com/users/franciscodelgadodev/events{/privacy}","received_events_url":"https://api.github.com/users/franciscodelgadodev/received_events","type":"User","site_admin":false},"body":":+1: \r\n","created_at":"2015-03-04T15:45:19Z","updated_at":"2015-03-04T15:45:19Z","html_url":"https://github.com/Herbalifedev/sinatra-admin/pull/31#discussion_r25784311","pull_request_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/comments/25784311"},"html":{"href":"https://github.com/Herbalifedev/sinatra-admin/pull/31#discussion_r25784311"},"pull_request":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31","id":30448004,"html_url":"https://github.com/Herbalifedev/sinatra-admin/pull/31","diff_url":"https://github.com/Herbalifedev/sinatra-admin/pull/31.diff","patch_url":"https://github.com/Herbalifedev/sinatra-admin/pull/31.patch","issue_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/31","number":31,"state":"closed","locked":false,"title":"ICM-2150","user":{"login":"ganya","id":75740,"avatar_url":"https://avatars.githubusercontent.com/u/75740?v=3","gravatar_id":"","url":"https://api.github.com/users/ganya","html_url":"https://github.com/ganya","followers_url":"https://api.github.com/users/ganya/followers","following_url":"https://api.github.com/users/ganya/following{/other_user}","gists_url":"https://api.github.com/users/ganya/gists{/gist_id}","starred_url":"https://api.github.com/users/ganya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganya/subscriptions","organizations_url":"https://api.github.com/users/ganya/orgs","repos_url":"https://api.github.com/users/ganya/repos","events_url":"https://api.github.com/users/ganya/events{/privacy}","received_events_url":"https://api.github.com/users/ganya/received_events","type":"User","site_admin":false},"body":"Refactor export csv. Please code review. Thanks.","created_at":"2015-03-04T09:02:27Z","updated_at":"2015-03-04T15:45:19Z","closed_at":"2015-03-04T09:10:44Z","merged_at":"2015-03-04T09:10:44Z","merge_commit_sha":"a081dc5cdc3b2431331c96986f9ae6d92a83a2c0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31/commits","review_comments_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31/comments","review_comment_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/31/comments","statuses_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/statuses/1d99487bd23f2ec712f525859d9c7224719c37f1","head":{"label":"Herbalifedev:ICM-2150","ref":"ICM-2150","sha":"1d99487bd23f2ec712f525859d9c7224719c37f1","user":{"login":"Herbalifedev","id":2192609,"avatar_url":"https://avatars.githubusercontent.com/u/2192609?v=3","gravatar_id":"","url":"https://api.github.com/users/Herbalifedev","html_url":"https://github.com/Herbalifedev","followers_url":"https://api.github.com/users/Herbalifedev/followers","following_url":"https://api.github.com/users/Herbalifedev/following{/other_user}","gists_url":"https://api.github.com/users/Herbalifedev/gists{/gist_id}","starred_url":"https://api.github.com/users/Herbalifedev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Herbalifedev/subscriptions","organizations_url":"https://api.github.com/users/Herbalifedev/orgs","repos_url":"https://api.github.com/users/Herbalifedev/repos","events_url":"https://api.github.com/users/Herbalifedev/events{/privacy}","received_events_url":"https://api.github.com/users/Herbalifedev/received_events","type":"Organization","site_admin":false},"repo":{"id":21748530,"name":"sinatra-admin","full_name":"Herbalifedev/sinatra-admin","owner":{"login":"Herbalifedev","id":2192609,"avatar_url":"https://avatars.githubusercontent.com/u/2192609?v=3","gravatar_id":"","url":"https://api.github.com/users/Herbalifedev","html_url":"https://github.com/Herbalifedev","followers_url":"https://api.github.com/users/Herbalifedev/followers","following_url":"https://api.github.com/users/Herbalifedev/following{/other_user}","gists_url":"https://api.github.com/users/Herbalifedev/gists{/gist_id}","starred_url":"https://api.github.com/users/Herbalifedev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Herbalifedev/subscriptions","organizations_url":"https://api.github.com/users/Herbalifedev/orgs","repos_url":"https://api.github.com/users/Herbalifedev/repos","events_url":"https://api.github.com/users/Herbalifedev/events{/privacy}","received_events_url":"https://api.github.com/users/Herbalifedev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Herbalifedev/sinatra-admin","description":"","fork":false,"url":"https://api.github.com/repos/Herbalifedev/sinatra-admin","forks_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/forks","keys_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/teams","hooks_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/hooks","issue_events_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/events{/number}","events_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/events","assignees_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/assignees{/user}","branches_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/branches{/branch}","tags_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/tags","blobs_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/languages","stargazers_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/stargazers","contributors_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/contributors","subscribers_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/subscribers","subscription_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/subscription","commits_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/contents/{+path}","compare_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/merges","archive_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/downloads","issues_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues{/number}","pulls_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/labels{/name}","releases_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/releases{/id}","created_at":"2014-07-11T19:26:02Z","updated_at":"2015-03-04T09:10:46Z","pushed_at":"2015-03-04T09:10:47Z","git_url":"git://github.com/Herbalifedev/sinatra-admin.git","ssh_url":"git@github.com:Herbalifedev/sinatra-admin.git","clone_url":"https://github.com/Herbalifedev/sinatra-admin.git","svn_url":"https://github.com/Herbalifedev/sinatra-admin","homepage":null,"size":577,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"Herbalifedev:master","ref":"master","sha":"424252134a202da93a7c8fe09e797aaa13c59f87","user":{"login":"Herbalifedev","id":2192609,"avatar_url":"https://avatars.githubusercontent.com/u/2192609?v=3","gravatar_id":"","url":"https://api.github.com/users/Herbalifedev","html_url":"https://github.com/Herbalifedev","followers_url":"https://api.github.com/users/Herbalifedev/followers","following_url":"https://api.github.com/users/Herbalifedev/following{/other_user}","gists_url":"https://api.github.com/users/Herbalifedev/gists{/gist_id}","starred_url":"https://api.github.com/users/Herbalifedev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Herbalifedev/subscriptions","organizations_url":"https://api.github.com/users/Herbalifedev/orgs","repos_url":"https://api.github.com/users/Herbalifedev/repos","events_url":"https://api.github.com/users/Herbalifedev/events{/privacy}","received_events_url":"https://api.github.com/users/Herbalifedev/received_events","type":"Organization","site_admin":false},"repo":{"id":21748530,"name":"sinatra-admin","full_name":"Herbalifedev/sinatra-admin","owner":{"login":"Herbalifedev","id":2192609,"avatar_url":"https://avatars.githubusercontent.com/u/2192609?v=3","gravatar_id":"","url":"https://api.github.com/users/Herbalifedev","html_url":"https://github.com/Herbalifedev","followers_url":"https://api.github.com/users/Herbalifedev/followers","following_url":"https://api.github.com/users/Herbalifedev/following{/other_user}","gists_url":"https://api.github.com/users/Herbalifedev/gists{/gist_id}","starred_url":"https://api.github.com/users/Herbalifedev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Herbalifedev/subscriptions","organizations_url":"https://api.github.com/users/Herbalifedev/orgs","repos_url":"https://api.github.com/users/Herbalifedev/repos","events_url":"https://api.github.com/users/Herbalifedev/events{/privacy}","received_events_url":"https://api.github.com/users/Herbalifedev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Herbalifedev/sinatra-admin","description":"","fork":false,"url":"https://api.github.com/repos/Herbalifedev/sinatra-admin","forks_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/forks","keys_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/teams","hooks_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/hooks","issue_events_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/events{/number}","events_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/events","assignees_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/assignees{/user}","branches_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/branches{/branch}","tags_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/tags","blobs_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/languages","stargazers_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/stargazers","contributors_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/contributors","subscribers_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/subscribers","subscription_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/subscription","commits_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/contents/{+path}","compare_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/merges","archive_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/downloads","issues_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues{/number}","pulls_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/labels{/name}","releases_url":"https://api.github.com/repos/Herbalifedev/sinatra-admin/releases{/id}","created_at":"2014-07-11T19:26:02Z","updated_at":"2015-03-04T09:10:46Z","pushed_at":"2015-03-04T09:10:47Z","git_url":"git://github.com/Herbalifedev/sinatra-admin.git","ssh_url":"git@github.com:Herbalifedev/sinatra-admin.git","clone_url":"https://github.com/Herbalifedev/sinatra-admin.git","svn_url":"https://github.com/Herbalifedev/sinatra-admin","homepage":null,"size":577,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31"},"html":{"href":"https://github.com/Herbalifedev/sinatra-admin/pull/31"},"issue":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/31"},"comments":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/Herbalifedev/sinatra-admin/statuses/1d99487bd23f2ec712f525859d9c7224719c37f1"}}}}