我很沮喪地使用Rails 3.2併爲Bootstrap modals做一個幫手。我不明白你什麼時候需要concat,而當你有時候我不知道標籤是否丟失,有時候我最終會得到一個包含before和ending標籤之間所有選項的散列。當我在任何帶do-end的內容標籤上使用concat時,所有地獄都會崩潰。所有我想要做的就是複製這個網站:深層嵌套的content_tag,concat和rails 3
<div id="stupid_modal" class="modal hide fade" tabindex="-1" data-width="760">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fontello-icon-cancel-1"></i></button>
<h4>Modal header</h4>
</div>
<div class="modal-body">
<div class="page-header">
<p>Test header 1 2 3.</p>
</div>
<div class="row-fluid">
content here... blah blah
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn">Close</button>
<button type="button" class="btn btn-green">Save changes</button>
</div>
</div>
我不能爲我的生命得到的模態頭中的H4按鈕得以順利實施。我也無法將頁眉顯示在模式主體中。
幫助我的是這樣的:
module ModalHelper
def modal(css_id, header_text, hidden = true, options = {},&block)
class_text = "modal"
class_text += " hide fade" if hidden
content_tag(:div, :class => 'modal hide fade', :id => css_id, :style => ("display:none;" if hidden)) do
concat modal_header(header_text)
concat modal_body(&block)
concat modal_footer
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,(content_tag(:i, :class => 'fontello-icon-cancel-1')),:class => 'close', :"data-dismiss" => 'modal', :"aria-hidden" => 'true')
concat content_tag(:h4, header_text)
end
end
def modal_body(page_header = "")
content_tag(:div, :class => 'modal-body') do
content_tag(:div, :class => 'page-header') do
concat content_tag(:p, page_header)
end
content_tag(:div, :class => 'row-fluid') do
yield
end
end
end
def modal_footer
content_tag(:div, :class => 'modal-footer') do
concat content_tag(:button, 'Close', type: "button", :class => 'btn btn-boo', :"data-dismiss" => 'modal')
concat content_tag(:button, 'Save', type: "button", class: 'btn btn-green')
end
end
末
和鏈接看起來是這樣的:
<%= modal_link "New Stupid Modal", "stupid_modal" %>
而HTML模式是這樣的:
<%= modal('stupid_modal', 'Shouldnt this work?', submit: true, tabindex: '-1') do %>
<% render 'stupid_modal_partials/stupid_modal' %>
<% end %>
outp UT是這樣的:
<button aria-hidden="true" class="close" data-dismiss="modal"><i>{:class=>"fontello-icon-cancel-1"}</i></button>
看起來像這樣在頁面的源代碼:
<i>{:class=>"fontello-icon-cancel-1"}</i>
更新:
改變modal_header到這個工程:
def modal_header(header_text)
content_tag(:div, :class => 'modal-header') do
concat content_tag(:button,(content_tag(:i, "",:class => 'fontello-icon-cancel-1')),:class => 'close', :"data-dismiss" => 'modal', :"aria-hidden" => 'true')
concat content_tag(:h4, header_text)
end
end
但這不:
def modal_header(header_text)
content_tag(:div, :class => 'modal-header') do
concat content_tag(:button,:class => 'close', :"data-dismiss" => 'modal', :"aria-hidden" => 'true') do
concat content_tag(:i, "",:class => 'fontello-icon-cancel-1')
end
concat content_tag(:h4, header_text)
end
end
哪個問題,wzup與concat?並且我錯過了一些東西 - 我還嘗試了空引號作爲按鈕的第二個參數content_tag
而且我已經試過按鈕標記的content_tag do-end內的i標記而不是內聯。沒愛。 – 2013-04-09 06:20:10
本文解釋'concat'和'capture'的用戶:http://thepugautomatic.com/2013/06/helpers/ – 2014-10-16 10:44:06