Class: Grapple::Components::Actions

Inherits:
HtmlComponent show all
Defined in:
lib/grapple/components/actions.rb

Overview

Render links that apply to the table

Examples:

<%
  actions = [
    { label: :new_user, url: new_user_path },
    { label: :export_users, url: export_users_path }
  ]
%>
<%= table_for(columns, @users) do |t| %>
  <%= t.header do %>
    <%= t.toolbar do %>
      <%= t.actions actions %>
    <% end %>
   <%= t.column_headings %>
  <% end %>
<% end %>

Instance Attribute Summary

Attributes inherited from BaseComponent

#builder, #columns, #params, #records, #template

Instance Method Summary collapse

Methods inherited from BaseComponent

#initialize, setting

Constructor Details

This class inherits a constructor from Grapple::Components::BaseComponent

Instance Method Details

#render(actions = [], &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/grapple/components/actions.rb', line 24

def render(actions = [], &block)
  html = capture_block(&block)
  actions.each do |action|
    if action.kind_of?(String)
      html << action
    else
      label = t(action[:label])
      url = action[:url]
      html_attr = action.dup
      html_attr.delete(:label)
      html_attr.delete(:url)
      html << template.send(link_to_helper, label, url, html_attr)
    end
  end      
  (:div, html.html_safe, class: 'actions')
end