Rails:Bootstrap下拉菜单不起作用 [英] Rails: Bootstrap dropdown menu not working

查看:128
本文介绍了Rails:Bootstrap下拉菜单不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢Rails,并且一直遵循Michael Hartl的教程。一切都一直很好,直到我下载菜单,这是不工作,然后工作,现在不工作:(我已经阅读了几个帖子和修复,我怀疑我的修补已经得到这个点很简单,我已经做了一些工作来阻止它的工作。
我会说,我最初在我的宝石文件中有bootstrap-sass 2.x,然后更改为3.x,但是返回到2.x,因为我没有意识到去3.x会导致由于类名称更改导致的问题,所以也许这个工作的时候是当我安装了bootstrap-sass 3.x,不确定。我在Windows 8.1中开发,我不得不解决execjs的问题,特别是runtimes.rb文件,所以这里是我的细节:



Gemfile:

 源'https://rubygems.org'
ruby​​'1.9.3'
#Bundle edge Rails:gem'rails',github:'rails / rails'
gem'rails','4.0.2'
gem'bootstrap-sass','2.3.2.0'
gem'链轮','2.11.0'
gem'bcrypt-ruby','3.1.2'

#使用sqlite3作为Active Record的数据库
gem'mysql2','0.3.15'

#使用SCSS作为样式表
gem'sass-rails','4.0.1'

#使用Uglifier作为JavaScript资产的压缩器
gem'uglifier','1.3。 0'

#使用CoffeeScript为.js.coffee资产和视图
gem'coffee-rails','4.0.1'

#参见https: /github.com/sstephenson/execjs#readme获取更多支持的运行时
#gem'therubyracer',平台::ruby

#使用jquery作为JavaScript库
gem'jquery -rails'

#Turbolinks更快地在您的Web应用程序中创建以下链接。阅读更多:https://github.com/rails/turbolinks
gem'turbolinks'

#轻松构建JSON API。阅读更多:https://github.com/rails/jbuilder
gem'jbuilder','1.2'

application.js

  // = require jquery 
// = require jquery_ujs
// = require bootstrap
// = require turbolinks
// = require_tree。

_header.html.erb(下拉菜单中的哪个)

 < header class =navbar navbar-fixed-top navbar-inverse> 
< div class =navbar-inner>
< div class =container>
<%= link_toCatered Fit,root_path,id:logo%>
<! - <%= link_to image_tag(logo.jpg,width:25%),root_path%> - >
< nav>
< div class =nav pull-right>
<! - < li><%= link_toHome,root_path%>< / li>
< li><%= link_to帮助,help_path%>< / li> - >
<%if!signed_in? %GT;
< div class =navbar-form>
<%= form_for(:session,url:sessions_path)do | f | %GT;
< div class =span2 input-xlarge>
<%f.label:email%>
<%= f.text_field:电子邮件,占位符:电子邮件%>
< / div>
< div class =span2 input-small>
<%f.label:password%>
<%= f.password_field:密码,占位符:密码%>
< / div>
< div class =span2>
<%= f.submit登录,类:btn btn-primary%>
< / div>
<%end%>
<%else%>
< li><%= link_toUsers,'#'%>< / li>
< li id =fat-menuclass =dropdown>
< a href =#class =dropdown-toggledata-toggle =dropdown>
帐户< b class =caret>< / b>
< / a>
< ul class =dropdown-menu>
< li><%= link_to个人资料,current_user%>< / li>
< li><%= link_to设置,edit_user_path(current_user)%>< / li>
< li class =divider>< / li>
< li>
<%= link_to退出,signout_path,方法:删除%>
< / li>
< / ul>
< li><%= link_to登出,signout_path,方法:删除%>< / li>
< / li>
<%end%>
< / div>
< / nav>
< / div>
< / div>
< / header>

我在控制台窗口中看不到任何错误,除了其他所有工作都在下降之外



以下是网页的源代码:

 <!DOCTYPE html> 
< html>
< head>
< title> Ruby on Rails教程示例应用程序| Dave Williams< / title>
< link data-turbolinks-track =truehref =/ assets / application.cssmedia =all =stylesheet/>
< script data-turbolinks-track =truesrc =/ assets / application.js>< / script>
< meta content =authenticity_tokenname =csrf-param/>
< meta content =SlKTCvDr5MFLP0EkthJHQeGIw + Yp0oGUrxvAeQMnVts =name =csrf-token/>
<! - [if lt IE 9]>
< script src =http://html5shim.googlecode.com/svn/trunk/html5.js>< / script>
<![endif] - >
< / head>
< body>
< header class =navbar navbar-fixed-top navbar-inverse>
< div class =navbar-inner>
< div class =container>
< a href =/id =logo> Catered Fit< / a>
<! - < a href =/>< img alt =Logosrc =/ assets / logo.jpgwidth =25%/>< / a& ; - >
< nav>
< div class =nav pull-right>
<! - < li>< a href =/>首页< / a>< / li>
< li>< a href =/ help>帮助< / a>< / li> - >
< li>< a href =#> Users< / a>< / li>
< li id =fat-menuclass =dropdown>
< a href =#class =dropdown-toggledata-toggle =dropdown>
帐户< b class =caret>< / b>
< / a>
< ul class =dropdown-menu>
< li>< a href =/ users / 1>个人资料< / a>< / li>
< li>< a href =/ users / 1 / edit>设置< / a>< / li>
< li class =divider>< / li>
< li>
< a data-method =deletehref =/ signout =nofollow>退出< / a>
< / li>
< / ul>
< li>< a data-method =deletehref =/ signout =nofollow>退出< / a>< / li>
< / li>
< / div>
< / nav>
< / div>
< / div>
< / header>
< div class =container>
< div class =row>
< aside class =span4>
< section>
< h1>
< img alt =Dave Williamsclass =gravatarsrc =https://secure.gravatar.com/avatar/387593e03fccc38895fc20a2084e27f5?s=50/>
Dave Williams
< / h1>
< / section>
< / aside>
< / div>

< footer class =footer>
< small>
< a href =http://railstutorial.org/> Rails教程< / a>
by Michael Hartl
< / small>
< nav>
< ul>
< li>< a href =/ about>关于< / a>< / li>
< li>< a href =/ contact>联系人< / a>< / li>
< li>< a href =http://news.railstutorial.org/>新闻< / a>< / li>
< / ul>
< / nav>
< / footer>
< pre class =debug_dump> ---!ruby / hash:ActionController ::参数
action:show
controller:users
id:&#39 1安培;#39;
< / pre>
< / div>
< / body>
< / html>

真的很感激一些帮助,以解决这个问题。



提前感谢,如果我能提供更多信息,请通知我。

解决方案

是可以确定的问题是我放在assets / javascript目录中的2个胭脂js文件。即bootstrap.js和bootstrap.min.js。一旦我删除了这些文件,下拉菜单再次工作。


I am quite new to Rails and have been following the tutorial by Michael Hartl. Everything has been going along really well until I got to the drop down menu, which was wasn't working, then was working and now isn't working :( I've read several posts and fixes and I suspect my tinkering has gotten to the point where quite simply, I've done something to stop it working. I will say that I initially had the bootstrap-sass 2.x in my gem file, then changed it to 3.x, but went back to 2.x because I didn't realise that going to 3.x would result in issues due to class name changes. So, perhaps the time this was working was when I had bootstrap-sass 3.x installed, not sure. From what I can tell though everything is set up the way it needs to be. I am developing under Windows 8.1 and I had to fix an issue with execjs and in specific the runtimes.rb file. So, here are my details:

Gemfile:

source 'https://rubygems.org'
ruby '1.9.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
gem 'bootstrap-sass', '2.3.2.0'
gem 'sprockets', '2.11.0'
gem 'bcrypt-ruby', '3.1.2'

# Use sqlite3 as the database for Active Record
gem 'mysql2', '0.3.15'

# Use SCSS for stylesheets
gem 'sass-rails', '4.0.1'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '4.0.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '1.2'

application.js

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

_header.html.erb (where the drop down is)

<header class="navbar navbar-fixed-top navbar-inverse">
  <div class="navbar-inner">
    <div class="container">
      <%= link_to "Catered Fit", root_path, id: "logo" %>
<!--      <%= link_to image_tag("logo.jpg", width: "25%"), root_path %>    -->
      <nav>
        <div class="nav pull-right">
<!--          <li><%= link_to "Home", root_path %></li>
          <li><%= link_to "Help", help_path %></li>   -->
          <% if !signed_in? %>
            <div class="navbar-form">
            <%= form_for(:session, url: sessions_path) do |f| %>
              <div class="span2 input-xlarge">
                <% f.label :email %>
                <%= f.text_field :email, placeholder: "Email" %>
              </div>
              <div class="span2 input-small">
                <% f.label :password %>
                <%= f.password_field :password, placeholder: "Password" %>
              </div>
              <div class="span2">
                <%= f.submit "Sign in", class: "btn btn-primary" %>
              </div>
            <% end %>
          <% else %>  
            <li><%= link_to "Users", '#' %></li>
            <li id="fat-menu" class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                Account <b class="caret"></b>
              </a>
              <ul class="dropdown-menu">
                <li><%= link_to "Profile", current_user %></li>
                <li><%= link_to "Settings", edit_user_path(current_user) %></li>
                <li class="divider"></li>
                <li>
                  <%= link_to "Sign out", signout_path, method: "delete" %>
                </li>
              </ul>
              <li><%= link_to "Sign out", signout_path, method: "delete" %></li>
            </li>
          <% end %>
        </div>
      </nav>
    </div>
  </div>
</header>

I don't see any errors in the console window and apart from the drop down everything else is working fine.

The following is the source code from the webpage:

<!DOCTYPE html>
<html>
  <head>
    <title>Ruby on Rails Tutorial Sample App | Dave Williams</title>
    <link data-turbolinks-track="true" href="/assets/application.css" media="all" rel="stylesheet" />
    <script data-turbolinks-track="true" src="/assets/application.js"></script>
    <meta content="authenticity_token" name="csrf-param" />
<meta content="SlKTCvDr5MFLP0EkthJHQeGIw+Yp0oGUrxvAeQMnVts=" name="csrf-token" />
    <!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
  </head>
  <body>
    <header class="navbar navbar-fixed-top navbar-inverse">
  <div class="navbar-inner">
    <div class="container">
      <a href="/" id="logo">Catered Fit</a>
<!--      <a href="/"><img alt="Logo" src="/assets/logo.jpg" width="25%" /></a>    -->
      <nav>
        <div class="nav pull-right">
<!--          <li><a href="/">Home</a></li>
          <li><a href="/help">Help</a></li>   -->
            <li><a href="#">Users</a></li>
            <li id="fat-menu" class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                Account <b class="caret"></b>
              </a>
              <ul class="dropdown-menu">
                <li><a href="/users/1">Profile</a></li>
                <li><a href="/users/1/edit">Settings</a></li>
                <li class="divider"></li>
                <li>
                  <a data-method="delete" href="/signout" rel="nofollow">Sign out</a>
                </li>
              </ul>
              <li><a data-method="delete" href="/signout" rel="nofollow">Sign out</a></li>
            </li>
        </div>
      </nav>
    </div>
  </div>
</header>
    <div class="container">
      <div class="row">
  <aside class="span4">
    <section>
      <h1>
        <img alt="Dave Williams" class="gravatar" src="https://secure.gravatar.com/avatar/387593e03fccc38895fc20a2084e27f5?s=50" />
        Dave Williams
      </h1>
    </section>
  </aside>
</div>

      <footer class="footer">
  <small>
    <a href="http://railstutorial.org/">Rails Tutorial</a>
    by Michael Hartl
  </small>
  <nav>
    <ul>
      <li><a href="/about">About</a></li>
      <li><a href="/contact">Contact</a></li>
      <li><a href="http://news.railstutorial.org/">News</a></li>
    </ul>
  </nav>
</footer>
      <pre class="debug_dump">--- !ruby/hash:ActionController::Parameters
action: show
controller: users
id: &#39;1&#39;
</pre>
    </div>
  </body>
</html>

Would really appreciate some help on this to get past this issue.

Thanks in advance, and please let me know if I can provide anymore information.

解决方案

What I was able to determine was the issue was 2 rouge js files that I had placed in the assets/javascript directory. Namely, bootstrap.js and bootstrap.min.js. Once I removed these files the dropdown was working again.

这篇关于Rails:Bootstrap下拉菜单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆