7

我似乎找不到任何关于为什么我的模态不显示的答案,所以我认为应该检查基础知识。我已经实现了以下结构,但没有弹出模式。请帮忙

1) 索引页面有一个链接,可以调用控制器的编辑操作

<%= link_to 'Edit business', edit_user_business_path(@u, b), {:remote => true, 'data-controls-modal' =>  "modal-window", 'data-backdrop' => true, 'data-keyboard' => true, :class => "btn btn-primary ", :id => 'edit_biz'} %>

2)控制器的编辑操作这样做(缩短):

respond_to do |format|
    format.html  {render :edit}
    format.json { head :ok}
  end

3) Edit.html.erb 看起来像这样:

<div class="modal hide fade" id="modal-window">
  <div class="modal-header">
    <a href="#" class="close">×</a>
    <h6>Loading...</h6>
  </div>

  <div class="modal-body center">

    <h2>Edit business </h2>
    <%= render 'editbusiness' %>
  </div>

  <div class="modal-footer">&nbsp;
  </div>
</div>

4) _editbusiness.html.erb 有以下内容

<fieldset>
<br/>
<br/>
<%= form_for @businesses_to_edit, :url => { :action => "edit"}, :class => "form-horizontal" do |biz| %>
    <p>
        <%=  biz.label :name, :class => "span3"%>
        <%=  biz.text_field(:name, :placeholder => biz.object.name, :class => "span3")%>
    </p>

    <p>
        <%=  biz.label :description, :class => "span3" %>
        <%=  biz.text_field(:description, :placeholder => biz.object.description, :class => "span3")%>
    </p>

    <br/>
    <br/>
    <br/>
    <div class="form-inline pull-right">
        &nbsp;&nbsp;<%=  biz.submit "Save", :class => "btn btn-inverse span1", :id => 'edit_biz' %>
        &nbsp;&nbsp;<%=  biz.button "Close", :class => "span1", :id => 'close' %>
    </div>

    <% end %>


    </fieldset>

5) 最后,application.js 有这个:

//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap


$(document).ready(function() {

$('#modal-window').modal('show')   ;
$('.modal-body').html('<%= escape_javascript(render :partial => "editbusiness", :object => @businesses_to_edit) %>');

});
4

1 回答 1

1

也许你需要包含在你的application.js这个字符串中:

//= require bootstrap-modal
于 2012-06-01T08:57:04.713 回答