Module: Shoehorn::Helpers::ModalHelpers

Defined in:
lib/shoehorn/helpers/modal_helpers.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_modal(options = {}) {|elements| ... } ⇒ Object

Render a modal popup

Returns HTML String for the modal popup

Examples:

bootstrap_modal(id: "a_dom_id", fade: true, title: "Modal title!") do |modal|
  modal.body do |c|
    c.render partial: 'disclamer'
  end
  modal.footer do |c|
    c.bootstrap_button "Close", "#", type: 'danger', html_options: { data: { dismiss: "modal" } }
    c.bootstrap_button "Accept",  accept_request_path(@request),
                       icon_name: 'ok', type: 'success',
                       html_options: { data: { dismiss: "modal" }, method: :put }
  end
end

To render the button to show the modal use:

bootstrap_button "Show Modal", "#a_dom_id", :html_options => { data: { toggle: "modal" }}

Parameters:

  • options (Hash) (defaults to: {})

    hash containing options (default: { :dom_id => ‘twitter-bootstrap-modal’, :fade => false, :header_title => ” }): :id - DOM ID of the modal element (mandatory). :fade - if true, add the fade class to the modal DOM element so the modal will be animated when shown. :title - modal title.

Yields:

  • (elements)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shoehorn/helpers/modal_helpers.rb', line 30

def bootstrap_modal(options = {})
  elements = Shoehorn::HelperCollectionSet.new(self, [:body, :footer])
  
  yield elements

  Shoehorn::Components::Modal.new(
    elements.collections[:body],
    elements.collections[:footer],
    options
  ).to_s
end