Rails 3.2.2 with Twitter Bootstrap Tabs Ajax not working

时光毁灭记忆、已成空白 提交于 2019-12-03 21:15:57

Ok, I figured this out. The correct link_to code is:

=link_to "Home", home_path(:format => :js), :remote => true, 'data-toggle' => 'tab'

And I needed to name the js file after the action in the controller, not the controller itself. So instead of calling it home.js I needed to call it index.js and it works.

One thing I noticed also was if I called it index.js.erb is would actually render the jquery code and not execute it. It would execute the alert though. Anyway, naming the file just index.js did the trick. Here was the final outcome for the index.js file:

$('.indexcontent').empty()
$('.indexcontent').append("<%= escape_javascript render(:file => 'home/index', :formats => [:html]) %>");

Bootstrap won't show the selected tab content, unless you set 'data-target'.

=link_to "Home", home_path(:format => :js), :remote => true, 'data-toggle' => 'tab', 'data-target' => '#indexcontent'


<div class="tab-content">
    <div class="tab-pane" id="indexcontent">
    </div>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!