diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 032c4c7b..7fba950e 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -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) @@ -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 diff --git a/log/development.log b/log/development.log index ab8b42e4..1051b03d 100644 --- a/log/development.log +++ b/log/development.log @@ -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 + [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m + [1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m +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"} + [1m[35m (2.1ms)[0m [1m[34mSELECT 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")[0m + ↳ app/controllers/articles_controller.rb:9:in `index' + [1m[36mArticle Load (0.4ms)[0m [1m[34mSELECT "articles".* FROM "articles" ORDER BY "articles"."created_at" DESC LIMIT ?[0m [["LIMIT", 3]] + ↳ app/controllers/articles_controller.rb:18:in `index' + [1m[36mCategory Load (1.0ms)[0m [1m[34mSELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?)[0m [["id", 12], ["id", 8]] + ↳ app/controllers/articles_controller.rb:18:in `index' + [1m[36mUser Load (0.5ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" IN (?, ?)[0m [["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) + [1m[36mUser Load (0.9ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?[0m [["id", 3], ["LIMIT", 1]] + ↳ app/views/articles/index.html.erb:16 + [1m[36mArticle Load (0.4ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE (id NOT IN (211,69,89)) ORDER BY "articles"."created_at" DESC LIMIT ? OFFSET ?[0m [["LIMIT", 10], ["OFFSET", 0]] + ↳ app/views/articles/index.html.erb:17 + [1m[36mCategory Load (0.2ms)[0m [1m[34mSELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?, ?, ?, ?)[0m [["id", 8], ["id", 5], ["id", 9], ["id", 10], ["id", 11], ["id", 12]] + ↳ app/views/articles/index.html.erb:17 + [1m[36mUser Load (0.2ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ?[0m [["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) + [1m[35m (0.6ms)[0m [1m[34mSELECT COUNT(*) FROM "articles" WHERE (id NOT IN (211,69,89))[0m + ↳ 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) + [1m[36mCategory Load (0.2ms)[0m [1m[34mSELECT "categories".* FROM "categories" ORDER BY "categories"."name" ASC[0m + ↳ 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"} + [1m[35m (0.5ms)[0m [1m[34mSELECT 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")[0m + ↳ app/controllers/articles_controller.rb:9:in `index' + [1m[36mArticle Load (1.3ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE "articles"."created_at" BETWEEN ? AND ? ORDER BY "articles"."created_at" DESC LIMIT ?[0m [["created_at", "2022-03-01"], ["created_at", "2022-04-01"], ["LIMIT", 3]] + ↳ app/controllers/articles_controller.rb:18:in `index' + [1m[36mCategory Load (0.8ms)[0m [1m[34mSELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?)[0m [["id", 11], ["id", 2], ["id", 5]] + ↳ app/controllers/articles_controller.rb:18:in `index' + [1m[36mUser Load (0.5ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ?[0m [["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) + [1m[36mUser Load (0.2ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?[0m [["id", 3], ["LIMIT", 1]] + ↳ app/views/articles/index.html.erb:16 + [1m[36mArticle Load (0.8ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE (id NOT IN (157,27,53)) AND "articles"."created_at" BETWEEN ? AND ? ORDER BY "articles"."created_at" DESC LIMIT ? OFFSET ?[0m [["created_at", "2022-03-01"], ["created_at", "2022-04-01"], ["LIMIT", 10], ["OFFSET", 0]] + ↳ app/views/articles/index.html.erb:17 + [1m[36mCategory Load (1.2ms)[0m [1m[34mSELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?, ?, ?, ?, ?)[0m [["id", 9], ["id", 2], ["id", 11], ["id", 10], ["id", 12], ["id", 8], ["id", 5]] + ↳ app/views/articles/index.html.erb:17 + [1m[36mCACHE User Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ?[0m [["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) + [1m[35m (3.0ms)[0m [1m[34mSELECT COUNT(*) FROM "articles" WHERE (id NOT IN (157,27,53)) AND "articles"."created_at" BETWEEN ? AND ?[0m [["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) + [1m[36mCategory Load (1.1ms)[0m [1m[34mSELECT "categories".* FROM "categories" ORDER BY "categories"."name" ASC[0m + ↳ 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"} + [1m[35m (0.4ms)[0m [1m[34mSELECT 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")[0m + ↳ app/controllers/articles_controller.rb:9:in `index' + [1m[36mArticle Load (0.3ms)[0m [1m[34mSELECT "articles".* FROM "articles" ORDER BY "articles"."created_at" DESC LIMIT ?[0m [["LIMIT", 3]] + ↳ app/controllers/articles_controller.rb:18:in `index' + [1m[36mCategory Load (0.7ms)[0m [1m[34mSELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?)[0m [["id", 12], ["id", 8]] + ↳ app/controllers/articles_controller.rb:18:in `index' + [1m[36mUser Load (1.2ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" IN (?, ?)[0m [["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) + [1m[36mUser Load (0.2ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?[0m [["id", 3], ["LIMIT", 1]] + ↳ app/views/articles/index.html.erb:16 + [1m[36mArticle Load (0.5ms)[0m [1m[34mSELECT "articles".* FROM "articles" WHERE (id NOT IN (211,69,89)) ORDER BY "articles"."created_at" DESC LIMIT ? OFFSET ?[0m [["LIMIT", 10], ["OFFSET", 0]] + ↳ app/views/articles/index.html.erb:17 + [1m[36mCategory Load (0.3ms)[0m [1m[34mSELECT "categories".* FROM "categories" WHERE "categories"."id" IN (?, ?, ?, ?, ?, ?)[0m [["id", 8], ["id", 5], ["id", 9], ["id", 10], ["id", 11], ["id", 12]] + ↳ app/views/articles/index.html.erb:17 + [1m[36mUser Load (0.6ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ?[0m [["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) + [1m[35m (0.7ms)[0m [1m[34mSELECT COUNT(*) FROM "articles" WHERE (id NOT IN (211,69,89))[0m + ↳ 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) + [1m[36mCategory Load (0.4ms)[0m [1m[34mSELECT "categories".* FROM "categories" ORDER BY "categories"."name" ASC[0m + ↳ 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) + + diff --git a/tmp/cache/bootsnap/compile-cache-iseq/4a/7eba3dd5405d63 b/tmp/cache/bootsnap/compile-cache-iseq/4a/7eba3dd5405d63 index 91367854..c669e037 100644 Binary files a/tmp/cache/bootsnap/compile-cache-iseq/4a/7eba3dd5405d63 and b/tmp/cache/bootsnap/compile-cache-iseq/4a/7eba3dd5405d63 differ