Skip to content
Ryuji EGUCHI edited this page Nov 21, 2019 · 11 revisions
# app/presenters/dashboard/sidebar_link_presenter.rb
module Dashboard
  class SidebarLinkPresenter < SimpleDelegator
    attr_reader :title, :url, :i_class, :options

    def initialize(view, title:, url:, i_class: nil)
      super(view)
      @title = title
      @url = url
      @i_class = i_class
      @options = options
    end

    def call
      content_tag(:li) do
        active_link_to(url, class: "b-dashboardSidebar__link", active: :exact, class_active: "is-current") do
          concat(content_tag(:i, nil, class: i_class))
          concat(title)
        end
      end
    end
  end
end
# app/views/layouts/_dashboard_sidebar.html.erb
<aside class="b-dashboardSidebar">
  <nav>
    <ul>
      <%= Dashboard::SidebarLinkPresenter.new(self, title: t('other.header.work'), url: "/dashboard/works", i_class: "i-dashboardWorks").call %>
    </ul>
  </nav>
</aside>
Clone this wiki locally