gpt4 book ai didi

ruby-on-rails - rails : Bootstrap dropdown menu not working

转载 作者:行者123 更新时间:2023-12-04 16:34:37 25 4
gpt4 key购买 nike

我是 Rails 的新手,一直在学习 Michael Hartl 的教程。一切都进行得非常顺利,直到我进入下拉菜单,该菜单不起作用,然后起作用,现在不起作用:(我已经阅读了几篇文章和修复程序,我怀疑我的修补已经到了很简单,我已经做了一些事情来阻止它工作。我会说我最初在我的 gem 文件中有 bootstrap-sass 2.x,然后将其更改为 3.x,但又回到了 2.x,因为我没有意识到转到 3.x 会导致问题由于类名更改。所以,也许这个工作的时间是我安装 bootstrap-sass 3.x 的时候,不确定。据我所知,虽然一切都按照需要的方式设置。我在 Windows 8.1 下开发,我必须解决 execjs 的问题,特别是 runtimes.rb 文件。所以,这是我的详细信息:

gem 文件:

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'

应用程序.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_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>

我在控制台窗口中没有看到任何错误,除了下拉菜单之外,其他一切都工作正常。

以下为网页源码:

<!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>

非常感谢能提供一些帮助来解决这个问题。

在此先感谢,如果我可以提供更多信息,请告诉我。

最佳答案

我将 app/assets/javascripts/application.js 中的指令顺序更改为:
//=需要jquery
//= 需要 jquery_ujs
//= 需要 Bootstrap
//= require_tree .

工作起来很有魅力:)

关于ruby-on-rails - rails : Bootstrap dropdown menu not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22974774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com