用户登录后,我想注销,鼠标点到用户名上,下拉菜单出不来。一点直接进入 users/admin 界面。
我用的是 rails s 启动的。
谢谢。
#4 楼 @huacnlee 就是鼠标点击 上面图片的 jinleileiking, 出不来下拉菜单,直接进入http://ruby-china.org/users/jinleileiking
有折腾了半天,还是没解决,跟踪到 bootstrap-dropdown.js, 如果在这个函数的 return false 处设断点,这个下拉菜单就出来
$.fn.dropdown = function ( selector ) {
return this.each(function () {
$(this).delegate(selector || d, 'click', function (e) {
var li = $(this).parent('li')
, isActive = li.hasClass('open')
clearMenus()
!isActive && li.toggleClass('open')
return false
})
})
}
过了这个函数,下拉菜单就没了。。高手帮忙看看啊。。郁闷
-_-#找到原因了,估计还是 assets-pipeline 的事。
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-alerts.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-dropdown.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tabs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-twipsy.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-buttons.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-popover.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.jdialog.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.timeago.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.timeago.settings.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.hotkeys.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.chosen.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.autogrow-textarea.js?body=1" type="text/javascript"></script>
<script src="/assets/social-share-button.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.at.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.caret.js?body=1" type="text/javascript"></script>
<script src="/assets/app.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
生成的 html 代码 application.js 和 bootstrap-dropdown 都挂了一次按钮触发事件,所以就打不开了。实际上是点了两次。。。。。。分析中。。。。郁闷啊
@jinleileiking 我觉得 @siyang1982 说的可能性比较大。程序代码,js 肯定是没有问题的。 其他人那都没有问题。 那就是跟你本地环境有问题...配置之类的...
#10 楼 @ichord 找到原因了 @siyang1982 @huacnlee 我的环境是 development, 所以 assets.debug = true .
所以 <%= javascript_include_tag "application" %> 被扩展为
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-alerts.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-dropdown.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tabs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-twipsy.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-buttons.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-popover.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.jdialog.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.timeago.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.timeago.settings.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.hotkeys.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.chosen.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.autogrow-textarea.js?body=1" type="text/javascript"></script>
<script src="/assets/social-share-button.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.at.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.caret.js?body=1" type="text/javascript"></script>
<script src="/assets/app.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
引起了事件触发两次。
难道你们都不用开发环境?
我看了 http://asciicasts.com/episodes/279-understanding-the-asset-pipeline 里面有个截图,debug 模式下确实是带 application.js 的
def javascript_include_tag(*sources)
pp sources
puts sources.class
options = sources.extract_options!
debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
body = options.key?(:body) ? options.delete(:body) : false
digest = options.key?(:digest) ? options.delete(:digest) : digest_assets?
t = sources.collect do |source|
if debug && asset = asset_paths.asset_for(source, 'js')
pp asset
asset.to_a.map { |dep|
pp dep
super(dep.pathname.to_s, { :src => path_to_asset(dep, :ext => 'js', :body => true, :digest => digest) }.merge!(options))
}
else
super(source.to_s, { :src => path_to_asset(source, :ext => 'js', :body => body, :digest => digest) }.merge!(options))
end
end.join("\n").html_safe
#p t
end
asset_paths.asset_fo 返回了 一个带 application.js 的数组。导致如此
#13 楼 @jinleileiking 看上去是 precompile 的 asset 导致的,你清空 public/assets 然后清理一下浏览器缓存就能够恢复正常。开发环境下请求获得的 application.js 内容不应该包含其他 js。