0

我不知道如何将模态放入部分中。请帮帮我 !

我有按钮:

 <a class="btn btn-large" data-toggle="modal" href="#show_me_modal"
 onclick="printpage()">Name of button<sup>TM</sup> message in action</a>

和 div 模态:

    <div class="modal hide fade" id="show_me_modal">
     <div class="modal-header">
      <a class="close" data-dismiss="modal">×</a>
         </div>
      <div class="modal-body">
      <p>some text</p>

      <ul class="media-grid">
        <%= image_tag("/images/pic02.png") %>
      </ul>

    </div>

    <div class="modal-footer">
      <b><%= link_to "#", '#' %></b>          
    </div>
  </div>
4

1 回答 1

2

ModalHelper为一个项目创建了。它有助于动态创建模态和指向它们的链接。希望对您有所帮助:

帮助代码:

创建文件 app/helpers/modal_helper.rb

module ModalHelper
    def modal(css_id, header_text, hidden = true, &block)
        content_tag(:div, :class => 'modal', :id => css_id, :style => ("display:none;" if hidden) ) do
            concat modal_header(header_text)
            concat modal_body(&block)
        end
    end

    def modal_button(link_text, href)
        modal_caller link_text, href, :button
    end

    def modal_link(link_text, href)
        modal_caller link_text, href
    end

    private

    def modal_caller(link_text, href, type = nil)
        options = { :"data-toggle" => "modal" }
        options.merge!({ :class => "btn" }) if type == :button
        link_to link_text, "#" + href, options
    end

    def modal_header(header_text)
        content_tag(:div, :class => 'modal-header') do
            concat content_tag(:button, 'x', :class => 'close', :"data-dismiss" => 'modal')
            concat content_tag(:h3, header_text)
        end
    end

    def modal_body
        content_tag(:div, :class => 'modal-body') do
            yield
        end     
    end 
end

模态链接:

生成指向您的模态的链接。

<%= modal_link('Sign up', "myModal") %>

渲染到模态:

包含您要呈现的代码。

<%= modal('myModal', 'Registration') do %>
    <% render 'devise/registrations/register' %>
<% end %>
于 2012-05-29T14:15:33.667 回答