[英]Foundation 5 top-bar in Rails app not working
After trying different examples and running over my code many, many times, I cannot figure out why the drop-down menu on my top-bar isn't functional. 在尝试了不同的示例并多次运行我的代码后,我无法弄清楚为什么我的顶栏上的下拉菜单不起作用。 I've tried the 'no-data-turbolinks' trick which came up in every search, to no avail. 我尝试过每次搜索都出现的'无数据 - 涡轮连接'技巧,但无济于事。
I've also tried adding jquery.turbolinks. 我也尝试过添加jquery.turbolinks。 It's getting pretty frustrating. 它变得非常令人沮丧。
I've even loaded the html for Zurb's own top-bar example. 我甚至为Zurb自己的顶级示例加载了html。 No worky-worky. 没有任何工作。
I'm using Rails 4.2.0, jquery-rails and foundation-rails 5.5.0. 我正在使用Rails 4.2.0,jquery-rails和foundation-rails 5.5.0。
I'm not sure what code to include, so if you have any questions, I'll be happy to incorporate it if you need it. 我不确定要包含哪些代码,所以如果您有任何问题,我很乐意在您需要的时候加入它。
<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>
<!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>
// 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(); });
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 %>
After running rails g foundation:install
and allowing the command to overwrite the main application ERB file, you'll end up with a turbolinks code in your javascript_include_tag. 运行rails g foundation:install
并允许命令覆盖主应用程序ERB文件后,您最终会在javascript_include_tag中使用turbolinks代码。
In your application.html.erb, change this... 在您的application.html.erb中,更改此...
<%= javascript_include_tag "application" 'data-turbolinks-track' => true %>
to this... 对...
<%= javascript_include_tag "application" %>
This single line code change should fix it. 这个单行代码更改应该修复它。 It worked for me. 它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.