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> 

回答

2

我已經創建ModalHelper一個項目。它有助於動態創建模式和鏈接。希望它可以幫助你:

助手代碼:

創建文件app /傭工/ 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 %> 
+0

感謝您的幫助,但意味着modal_link? 我應該寫LINK這個<%= link_to「註冊」,「myModal」%>或者什麼? 當我把你的代碼(渲染到模態) 未定義的方法'模態' 而我應該只是把我的模態股份進入Regitration形式是? – skrypalyk

+0

'modal_link'生成鏈接到您的模型(鏈接到源)。檢查'modal_caller'方法來理解我在說什麼。 'modal'方法是Helper方法,它應該可以在你的視圖中訪問,在Rails 3中,Helper被自動包含並且可以在所有視圖中訪問。 – thesis

+0

你讀過我的代碼嗎? 'modal_caller'在那裏。你創建了modal_helper.rb嗎? – thesis

相關問題