diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 0000000..9afffd7 --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class TagsController < ApplicationController + skip_before_action :require_login, only: [:index, :show] + before_action :set_tag, only: [:show] + + def index + @tags = Tag.all + .page(params[:page]) + end + + def show; end + + private + + def set_tag + @tag = Tag.find_by(name: params[:id]) + end +end diff --git a/app/models/tag.rb b/app/models/tag.rb index c15af97..320e815 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -4,4 +4,8 @@ class Tag < ApplicationRecord validates :name, presence: true has_many :microposts_tags has_many :microposts, through: :microposts_tags + + def to_param + name + end end diff --git a/app/views/microposts/_micropost.html.erb b/app/views/microposts/_micropost.html.erb index dbe88a5..987ee63 100644 --- a/app/views/microposts/_micropost.html.erb +++ b/app/views/microposts/_micropost.html.erb @@ -4,7 +4,7 @@
<%= t(".empty") %>
+<% else %> + + <%= paginate @tags %> +<% end %> diff --git a/app/views/tags/show.html.erb b/app/views/tags/show.html.erb new file mode 100644 index 0000000..a06558a --- /dev/null +++ b/app/views/tags/show.html.erb @@ -0,0 +1,3 @@ +