Skip to content

Instantly share code, notes, and snippets.

@blamattina
Created June 2, 2012 23:48
Show Gist options
  • Save blamattina/2860540 to your computer and use it in GitHub Desktop.
Save blamattina/2860540 to your computer and use it in GitHub Desktop.
helper method to create modals with twitter bootstrap
# use on its own
<%= create_modal("modal","Modal Header", render("modal")) %>
# or as part of another helper
def modal_link_with_modal
modal_id = "modal"
link_to("Modal", "##{modal_id}", :data => { :toggle => "modal" }) +
create_modal(modal_id, "Modal Header", render("modal"), true)
end
# helper method
def create_modal(modal_id, header, body, footer = false)
content_tag(:div, :class => "modal hide", :id => "#{modal_id}") do
content_tag(:div, :class => "modal-header") do
content_tag(:a, "x", :class => "close", :data => { :dismiss => "modal"}) +
content_tag(:h3, header)
end +
content_tag(:div, :class => "modal-body") do
body.html_safe
end +
if footer
content_tag(:div, :class => "modal-footer") do
link_to("Close", "##{modal_id}", :class => "btn", :data => { :toggle => "modal" })
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment