Created
June 2, 2012 23:48
-
-
Save blamattina/2860540 to your computer and use it in GitHub Desktop.
helper method to create modals with twitter bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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