Controller features

Coupdoeil::Hovercard allows the use of familiar interfaces from ActionController::Base like:

  • callbacks (before_action, around_action …)
  • rendering API (render, render_to_string)
  • helpers (and helper inclusion)
  • layout selection

Layout

Layout system is the same as for ActionController::Base. By default, it will be the "hovercard" layout, located in app/hovercards/layouts/hovercard.html.erb, but you can change this behavior with the layout method or the layout: option passed to render.

You can create new layouts for specific use-cases. For example, one main layout and one for tooltips, or action menus. Default directory is app/hovercards/layouts/. The layout template must call yield to render the content.

<div class="main-hovercard-layout">
  <%= yield %>
</div>

Note that the layout HTML element should not have a uniq CSS id as it can be rendered many times at once within the same document.

You can see different layout usage in examples.

Rendering

default

class ContactHovercard < ApplicationHovercard
  def summary
    # not specified, will render app/hovercards/contact_hovercard/summary.html.erb
  end
end

render another template

class ContactHovercard < ApplicationHovercard
  def details
  end
  
  def summary
    # will render app/hovercards/contact_hovercard/details.html.erb
    render :details
  end
end

render partial

class ContactHovercard < ApplicationHovercard
  def summary
    # will render app/hovercards/contact_hovercard/_business_card.html.erb, without layout
    render partial: "business_card"
  end
end

Remember that partials have their own layouts

Any renderable object, like a ViewComponent

class ContactHovercard < ApplicationHovercard
  def details
  end
  
  def summary
    render ContactSummaryComponent.new
  end
end