在尝试了不同的示例并多次运行我的代码之后,我无法弄清楚为什么我的顶栏上的下拉菜单不起作用。我试过每次搜索都会出现的"无数据涡轮链接"技巧,但无济于事。
我也试过添加jquery. turbollinks。这真是太令人沮丧了。
我甚至已经为Zurb自己的顶部栏示例加载了html。没有worky-worky。
我正在使用Rails 4.2.0, jquery-rails和foundation-rails 5.5.0。
我不确定要包含什么代码,所以如果你有任何问题,如果你需要的话,我很乐意合并它。
下面是我的_navbar.html。erb(这是一个来自基金会网站顶部栏的例子):
<nav class="top-bar" data-topbar role="navigation">
<ul class="title-area">
<li class="name">
<h1><a href="#">My Site</a></h1>
</li>
<!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>
<section class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="active"><a href="#">Right Button Active</a></li>
<li class="has-dropdown">
<a href="#">Right Button Dropdown</a>
<ul class="dropdown">
<li><a href="#">First link in dropdown</a></li>
<li class="active"><a href="#">Active link in dropdown</a></li>
</ul>
</li>
</ul>
<!-- Left Nav Section -->
<ul class="left">
<li><a href="#">Left Nav Button</a></li>
</ul>
</section>
</nav>
这是我的application.html.erb:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= content_for?(:title) ? yield(:title) : "foundation-rails" %></title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag "vendor/modernizr" %>
<%= javascript_include_tag "application" 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<%= render partial: "elements/navbar" %>
<body>
<%= yield %>
</body>
<%= render partial: "elements/footer" %>
</html>
和我的application.js文件(删除turbollinks的引用后):
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require foundation
//= require_tree .
$(function(){ $(document).foundation(); });
我的Gemfile(移除turbollinks后):
source 'https://rubygems.org'
gem 'rails', '>= 4.2.0'
group :test, :development do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'sqlite3', require: false
gem 'database_cleaner'
gem 'capybara'
end
group :production do
gem 'thin', require: false
gem 'pg', require: false
end
gem 'bundler'
gem 'foundation-rails', '>= 5.5'
gem 'sass-rails'
gem 'sass', '>= 3.3'
gem 'nav_lynx'
gem 'jbuilder', '~> 2.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'uglifier', '>= 1.3.0'
gem 'sdoc', '~> 0.4.0', group: :doc, require: false
gem 'spring', group: :development
尝试将此移动到关闭body
标记之前:
<%= javascript_include_tag "application" 'data-turbolinks-track' => true %>
运行rails g foundation:install
并允许命令覆盖主应用程序ERB文件后,您将在javascript_include_tag中最终获得turbollinks代码。
在您的application.html。动词,改变这个…
<%= javascript_include_tag "application" 'data-turbolinks-track' => true %>
<%= javascript_include_tag "application" %>
这一行代码应该可以修复它。