Skip to content

Commit

Permalink
error correction
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusflorez committed Jul 25, 2022
1 parent 714965a commit 7041603
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ class ArticlesController < ApplicationController

before_action :authenticate_user!, except: %i[index show]
before_action :set_article, only: %i[edit update destroy]
before_action :set_categories, only: %i[new create edit update]
before_action :set_categories, only: %i[index new create edit update]

def index
@categories = Category.sorted
category = @categories.select { |c| c.name == params[:category] }[0] if params[:category].present?
@archives = Article.group_by_month(:created_at, format: '%B %Y', locale: :en).count

category = @categories.find { |c| c.name == params[:category] } if params[:category].present?
month_year = @archives.find { |m| m[0] == params[:month_year] }&.first if params[:month_year].present?

@highlights = Article.includes(:category, :user)
.filter_by_category(category)
.filter_by_archive(params[:month_year])
.filter_by_archive(month_year)
.desc_order
.first(3)

Expand All @@ -20,11 +22,10 @@ def index
@articles = Article.includes(:category, :user)
.without_highlights(highlight_ids)
.filter_by_category(category)
.filter_by_archive(params[:month_year])
.filter_by_archive(month_year)
.desc_order
.page(current_page)

@archives = Article.group_by_month(:created_at, format: '%B %Y', locale: :en).count
end

def show
Expand Down
175 changes: 175 additions & 0 deletions log/development.log
Original file line number Diff line number Diff line change
Expand Up @@ -30763,3 +30763,178 @@ Processing by ArticlesController#index as HTML
Completed 200 OK in 494ms (Views: 358.4ms | ActiveRecord: 11.5ms | Allocations: 31152)


Started GET "/pt-BR" for 127.0.0.1 at 2022-07-25 12:22:44 -0300
 (0.5ms) SELECT sqlite_version(*)
 (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
DEPRECATION WARNING: 'include Pundit' is deprecated. Please use 'include Pundit::Authorization' instead.
(called from include at /home/mateus/projetos/ruby/projeto_mvc/app/controllers/application_controller.rb:2)
Processing by ArticlesController#index as HTML
Parameters: {"locale"=>"pt-BR"}
 (2.1ms) SELECT COUNT(*) AS count_all, strftime('%Y-%m-01', "articles"."created_at") AS strftime_y_m_01_articles_created_at FROM "articles" WHERE ("articles"."created_at" IS NOT NULL) GROUP BY strftime('%Y-%m-01', "articles"."created_at")
↳ app/controllers/articles_controller.rb:9:in `index'
Article Load (0.4ms) SELECT "articles".* FROM "articles" ORDER BY "articles"."created_at" DESC LIMIT ? [["LIMIT", 3]]
↳ app/controllers/articles_controller.rb:18:in `index'
Category Load (1.0ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?) [["id", 12], ["id", 8]]
↳ app/controllers/articles_controller.rb:18:in `index'
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" IN (?, ?) [["id", 3], ["id", 2]]
↳ app/controllers/articles_controller.rb:18:in `index'
Rendering layout layouts/application.html.erb
Rendering articles/index.html.erb within layouts/application
Rendered articles/_longer_featured.html.erb (Duration: 13.6ms | Allocations: 684)
Rendered articles/_article_detail.html.erb (Duration: 2.4ms | Allocations: 611)
Rendered articles/_medium_featured.html.erb (Duration: 15.3ms | Allocations: 1618)
Rendered articles/_article_detail.html.erb (Duration: 0.6ms | Allocations: 311)
Rendered articles/_medium_featured.html.erb (Duration: 6.4ms | Allocations: 600)
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 3], ["LIMIT", 1]]
↳ app/views/articles/index.html.erb:16
Article Load (0.4ms) SELECT "articles".* FROM "articles" WHERE (id NOT IN (211,69,89)) ORDER BY "articles"."created_at" DESC LIMIT ? OFFSET ? [["LIMIT", 10], ["OFFSET", 0]]
↳ app/views/articles/index.html.erb:17
Category Load (0.2ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?, ?, ?, ?) [["id", 8], ["id", 5], ["id", 9], ["id", 10], ["id", 11], ["id", 12]]
↳ app/views/articles/index.html.erb:17
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? [["id", 2]]
↳ app/views/articles/index.html.erb:17
Rendered articles/_article_detail.html.erb (Duration: 3.2ms | Allocations: 357)
Rendered articles/_article_detail.html.erb (Duration: 2.3ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 0.8ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 19.9ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 3.7ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 4.0ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 1.1ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 0.6ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 0.6ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 0.8ms | Allocations: 313)
Rendered collection of articles/_article.html.erb [10 times] (Duration: 112.3ms | Allocations: 7169)
 (0.6ms) SELECT COUNT(*) FROM "articles" WHERE (id NOT IN (211,69,89))
↳ app/views/articles/_pagination.html.erb:2
Rendered articles/_pagination.html.erb (Duration: 16.4ms | Allocations: 2315)
Rendered articles/_about.html.erb (Duration: 7.5ms | Allocations: 186)
Rendered articles/_archives.html.erb (Duration: 5.2ms | Allocations: 1792)
Rendered articles/_elsewhere.html.erb (Duration: 0.5ms | Allocations: 151)
Rendered articles/_right_side.html.erb (Duration: 33.1ms | Allocations: 2876)
Category Load (0.2ms) SELECT "categories".* FROM "categories" ORDER BY "categories"."name" ASC
↳ app/views/articles/index.html.erb:25
Rendered articles/index.html.erb within layouts/application (Duration: 307.9ms | Allocations: 27171)
[Webpacker] Everything's up-to-date. Nothing to do
Rendered layouts/_locale_links.html.erb (Duration: 69.5ms | Allocations: 316)
Rendered layouts/_account_links.html.erb (Duration: 6.4ms | Allocations: 517)
Rendered layouts/_topnavbar.html.erb (Duration: 95.4ms | Allocations: 2017)
Rendered layouts/_flash_messages.html.erb (Duration: 2.2ms | Allocations: 238)
Rendered layouts/_footer.html.erb (Duration: 0.5ms | Allocations: 187)
Rendered layout layouts/application.html.erb (Duration: 501.6ms | Allocations: 35969)
Completed 200 OK in 707ms (Views: 514.3ms | ActiveRecord: 19.5ms | Allocations: 77135)


Started GET "/pt-BR/articles?month_year=March+2022" for 127.0.0.1 at 2022-07-25 12:22:47 -0300
Processing by ArticlesController#index as HTML
Parameters: {"month_year"=>"March 2022", "locale"=>"pt-BR"}
 (0.5ms) SELECT COUNT(*) AS count_all, strftime('%Y-%m-01', "articles"."created_at") AS strftime_y_m_01_articles_created_at FROM "articles" WHERE ("articles"."created_at" IS NOT NULL) GROUP BY strftime('%Y-%m-01', "articles"."created_at")
↳ app/controllers/articles_controller.rb:9:in `index'
Article Load (1.3ms) SELECT "articles".* FROM "articles" WHERE "articles"."created_at" BETWEEN ? AND ? ORDER BY "articles"."created_at" DESC LIMIT ? [["created_at", "2022-03-01"], ["created_at", "2022-04-01"], ["LIMIT", 3]]
↳ app/controllers/articles_controller.rb:18:in `index'
Category Load (0.8ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?) [["id", 11], ["id", 2], ["id", 5]]
↳ app/controllers/articles_controller.rb:18:in `index'
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? [["id", 2]]
↳ app/controllers/articles_controller.rb:18:in `index'
Rendering layout layouts/application.html.erb
Rendering articles/index.html.erb within layouts/application
Rendered articles/_longer_featured.html.erb (Duration: 2.9ms | Allocations: 206)
Rendered articles/_article_detail.html.erb (Duration: 4.7ms | Allocations: 320)
Rendered articles/_medium_featured.html.erb (Duration: 18.9ms | Allocations: 627)
Rendered articles/_article_detail.html.erb (Duration: 0.6ms | Allocations: 311)
Rendered articles/_medium_featured.html.erb (Duration: 3.8ms | Allocations: 601)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 3], ["LIMIT", 1]]
↳ app/views/articles/index.html.erb:16
Article Load (0.8ms) SELECT "articles".* FROM "articles" WHERE (id NOT IN (157,27,53)) AND "articles"."created_at" BETWEEN ? AND ? ORDER BY "articles"."created_at" DESC LIMIT ? OFFSET ? [["created_at", "2022-03-01"], ["created_at", "2022-04-01"], ["LIMIT", 10], ["OFFSET", 0]]
↳ app/views/articles/index.html.erb:17
Category Load (1.2ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?, ?, ?, ?, ?) [["id", 9], ["id", 2], ["id", 11], ["id", 10], ["id", 12], ["id", 8], ["id", 5]]
↳ app/views/articles/index.html.erb:17
CACHE User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? [["id", 2]]
↳ app/views/articles/index.html.erb:17
Rendered articles/_article_detail.html.erb (Duration: 4.5ms | Allocations: 315)
Rendered articles/_article_detail.html.erb (Duration: 1.7ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 2.6ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 4.1ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 4.3ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 3.4ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 6.4ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 0.7ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 2.9ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 4.9ms | Allocations: 314)
Rendered collection of articles/_article.html.erb [10 times] (Duration: 75.8ms | Allocations: 6922)
 (3.0ms) SELECT COUNT(*) FROM "articles" WHERE (id NOT IN (157,27,53)) AND "articles"."created_at" BETWEEN ? AND ? [["created_at", "2022-03-01"], ["created_at", "2022-04-01"]]
↳ app/views/articles/_pagination.html.erb:2
Rendered articles/_pagination.html.erb (Duration: 22.7ms | Allocations: 1235)
Rendered articles/_about.html.erb (Duration: 1.0ms | Allocations: 67)
Rendered articles/_archives.html.erb (Duration: 7.6ms | Allocations: 1526)
Rendered articles/_elsewhere.html.erb (Duration: 0.3ms | Allocations: 53)
Rendered articles/_right_side.html.erb (Duration: 16.9ms | Allocations: 1856)
Category Load (1.1ms) SELECT "categories".* FROM "categories" ORDER BY "categories"."name" ASC
↳ app/views/articles/index.html.erb:25
Rendered articles/index.html.erb within layouts/application (Duration: 228.8ms | Allocations: 20744)
[Webpacker] Everything's up-to-date. Nothing to do
Rendered layouts/_locale_links.html.erb (Duration: 6.0ms | Allocations: 133)
Rendered layouts/_account_links.html.erb (Duration: 2.4ms | Allocations: 219)
Rendered layouts/_topnavbar.html.erb (Duration: 24.0ms | Allocations: 691)
Rendered layouts/_flash_messages.html.erb (Duration: 1.0ms | Allocations: 61)
Rendered layouts/_footer.html.erb (Duration: 1.0ms | Allocations: 67)
Rendered layout layouts/application.html.erb (Duration: 278.8ms | Allocations: 24850)
Completed 200 OK in 339ms (Views: 276.4ms | ActiveRecord: 9.6ms | Allocations: 32247)


Started GET "/pt-BR/articles?month_year=fevereiro+2022" for 127.0.0.1 at 2022-07-25 12:22:56 -0300
Processing by ArticlesController#index as HTML
Parameters: {"month_year"=>"fevereiro 2022", "locale"=>"pt-BR"}
 (0.4ms) SELECT COUNT(*) AS count_all, strftime('%Y-%m-01', "articles"."created_at") AS strftime_y_m_01_articles_created_at FROM "articles" WHERE ("articles"."created_at" IS NOT NULL) GROUP BY strftime('%Y-%m-01', "articles"."created_at")
↳ app/controllers/articles_controller.rb:9:in `index'
Article Load (0.3ms) SELECT "articles".* FROM "articles" ORDER BY "articles"."created_at" DESC LIMIT ? [["LIMIT", 3]]
↳ app/controllers/articles_controller.rb:18:in `index'
Category Load (0.7ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?) [["id", 12], ["id", 8]]
↳ app/controllers/articles_controller.rb:18:in `index'
User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" IN (?, ?) [["id", 3], ["id", 2]]
↳ app/controllers/articles_controller.rb:18:in `index'
Rendering layout layouts/application.html.erb
Rendering articles/index.html.erb within layouts/application
Rendered articles/_longer_featured.html.erb (Duration: 1.8ms | Allocations: 152)
Rendered articles/_article_detail.html.erb (Duration: 2.0ms | Allocations: 312)
Rendered articles/_medium_featured.html.erb (Duration: 6.3ms | Allocations: 602)
Rendered articles/_article_detail.html.erb (Duration: 2.1ms | Allocations: 311)
Rendered articles/_medium_featured.html.erb (Duration: 6.6ms | Allocations: 600)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 3], ["LIMIT", 1]]
↳ app/views/articles/index.html.erb:16
Article Load (0.5ms) SELECT "articles".* FROM "articles" WHERE (id NOT IN (211,69,89)) ORDER BY "articles"."created_at" DESC LIMIT ? OFFSET ? [["LIMIT", 10], ["OFFSET", 0]]
↳ app/views/articles/index.html.erb:17
Category Load (0.3ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?, ?, ?, ?) [["id", 8], ["id", 5], ["id", 9], ["id", 10], ["id", 11], ["id", 12]]
↳ app/views/articles/index.html.erb:17
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? [["id", 2]]
↳ app/views/articles/index.html.erb:17
Rendered articles/_article_detail.html.erb (Duration: 2.7ms | Allocations: 315)
Rendered articles/_article_detail.html.erb (Duration: 1.9ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 2.7ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 1.8ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 0.8ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 1.5ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 2.9ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 1.9ms | Allocations: 314)
Rendered articles/_article_detail.html.erb (Duration: 1.7ms | Allocations: 313)
Rendered articles/_article_detail.html.erb (Duration: 2.4ms | Allocations: 313)
Rendered collection of articles/_article.html.erb [10 times] (Duration: 66.5ms | Allocations: 6921)
 (0.7ms) SELECT COUNT(*) FROM "articles" WHERE (id NOT IN (211,69,89))
↳ app/views/articles/_pagination.html.erb:2
Rendered articles/_pagination.html.erb (Duration: 4.8ms | Allocations: 1172)
Rendered articles/_about.html.erb (Duration: 0.2ms | Allocations: 67)
Rendered articles/_archives.html.erb (Duration: 4.7ms | Allocations: 1523)
Rendered articles/_elsewhere.html.erb (Duration: 0.8ms | Allocations: 53)
Rendered articles/_right_side.html.erb (Duration: 12.8ms | Allocations: 1853)
Category Load (0.4ms) SELECT "categories".* FROM "categories" ORDER BY "categories"."name" ASC
↳ app/views/articles/index.html.erb:25
Rendered articles/index.html.erb within layouts/application (Duration: 160.8ms | Allocations: 20498)
[Webpacker] Everything's up-to-date. Nothing to do
Rendered layouts/_locale_links.html.erb (Duration: 3.4ms | Allocations: 132)
Rendered layouts/_account_links.html.erb (Duration: 1.0ms | Allocations: 218)
Rendered layouts/_topnavbar.html.erb (Duration: 15.1ms | Allocations: 679)
Rendered layouts/_flash_messages.html.erb (Duration: 0.1ms | Allocations: 55)
Rendered layouts/_footer.html.erb (Duration: 0.1ms | Allocations: 67)
Rendered layout layouts/application.html.erb (Duration: 237.8ms | Allocations: 24457)
Completed 200 OK in 286ms (Views: 238.0ms | ActiveRecord: 5.3ms | Allocations: 31200)


Binary file modified tmp/cache/bootsnap/compile-cache-iseq/4a/7eba3dd5405d63
Binary file not shown.

0 comments on commit 7041603

Please sign in to comment.