rails 4 bootstrap 3 ajax modal

我正忙着学习Rails 4,当用户点击链接时我想显示一个bootstrap popup模式,当模态打开时,它需要显示与该特定记录有关的信息。 inheritance了我到目前为止所做的事情,这只是没有显示实际的模态弹出窗口确实传递了正确的参数。

index.html.erb页面有:

 'modal', :"data-target" => '#myModal' %>  

我还有一个作品/ _modal.html.erb:

  

也是一个工程控制者:

  def show @work = Work.find(params[:id]) if request.xhr? respond_to do |format| format.html {render :partial => 'modal'} format.json {head :ok} end end end 

最后是作品/ show.js.erb:

 $("#myModal").html(""); 

我希望我在这里容易丢失一些东西。 在控制台中我可以看到以下消息,所以我知道它返回正确的信息,但不幸的是它没有显示模式:

 Started GET "/works/8" for 127.0.0.1 at 2014-03-03 09:31:12 +0000 Processing by WorksController#show as JS Parameters: {"id"=>"8"} Work Load (0.2ms) SELECT "works".* FROM "works" WHERE "works"."id" = ? LIMIT 1 [["id", 8]] Rendered works/_modal.html.erb (4.9ms) Completed 200 OK in 8ms (Views: 6.3ms | ActiveRecord: 0.2ms) 

非常感谢任何帮助。

尝试另一种方式。 通过这种方式,我们将使用显式javascript命令显示模式弹出窗口。

在index.html.erb中

 <%= link_to "view", work_path(w), remote: true, class: 'static-popup-link'%>  

在application.js中

 $(document).ready(function() { var clickOnPopupLink = function(){ $('body').on('click', '.static-popup-link', function(){ $('#myModal').modal('show'); }); } clickOnPopupLink(); }); 

在控制器中

 def show @work = Work.find(params[:id]) end 

在show.js.erb中

 $('#myModal').html("<%= j render("/works/modal")%>") 

你还需要显示模态,在$('#myModal').modal('show')添加$('#myModal').modal('show')

 $("#myModal").html("<%= escape_javascript(render 'modal') %>"); $('#myModal').modal('show')