我正在切换到Twitter Bootstrap 2.1.1。
我有一个带有删除按钮的模态,但它不起作用。在以前的引导程序版本中,它运行良好。Rails版本是3.1
这是代码
<a title="<%= t('delete') %>" id="delete" class="label" href="#myModal-<%= post.id %>" data-toggle="modal"><%= t('delete') %></a>
模态
<div class="modal hide" id="myModal-<%= post.id %>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><%= t('delete_this_question') %></h3>
</div>
<div class="modal-body">
<p><%= raw post.text %></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><%= t('cancel') %></button>
<%= link_to(t('delete'), { :controller => 'posts', :action => 'destroy', :id => post.id } ,:method => :delete, :class => 'btn btn-primary') %>
</div>
</div>
但它不起作用。Rails收到一个GET并显示帖子,但它并没有破坏它
知道吗?感谢
我在http://rors.org/demos/custom-confirm-in-rails
您可以完全不引人注目地使用它,而不必在视图中有自定义的删除链接或模态内容。因此,在我看来,我有了标准的Rails链接(只添加了一些类来使用Bootstrap样式):
link_to 'delete', post, method: :delete, confirm: 'Are you sure?', class: 'btn btn-mini btn-danger'
下面是/app/assets/javascripts/bootstrap-confirmation.js.coffee
$.rails.allowAction = (link) ->
return true unless link.attr('data-confirm')
$.rails.showConfirmDialog(link) # look bellow for implementations
false # always stops the action since code runs asynchronously
$.rails.confirmed = (link) ->
link.removeAttr('data-confirm')
link.trigger('click.rails')
$.rails.showConfirmDialog = (link) ->
message = link.attr 'data-confirm'
html = """
<div class="modal" id="confirmationDialog">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Request confirmation</h3>
</div>
<div class="modal-body">
<p>#{message}</p>
</div>
<div class="modal-footer">
<a data-dismiss="modal" class="btn">Cancel</a>
<a data-dismiss="modal" class="btn btn-danger confirm">Confirm</a>
</div>
</div>
"""
$(html).modal()
$('#confirmationDialog .confirm').on 'click', -> $.rails.confirmed(link)
如果你想在你的模态中包含更多特定于帖子的细节,你可以随时将它们作为数据属性包含在你的删除链接中(就像data-confirm
用于显示确认消息一样)