Rails应用程序中的Foundation 5顶级栏无法正常工作

时间:2015-06-10 09:46:34

标签: jquery css ruby-on-rails zurb-foundation-5

在尝试不同的示例并多次运行我的代码之后,我无法弄清楚为什么顶栏上的下拉菜单不起作用。我已经尝试了“无数据 - 涡轮连接”和#39;在每次搜索中出现的技巧都无济于事。

我也尝试过添加jquery.turbolinks。它变得非常令人沮丧。

我甚至为Zurb自己的顶级示例加载了html。没有工作。

我使用的是Rails 4.2.0,jquery-rails和foundation-rails 5.5.0。

我不确定要包含哪些代码,因此如果您有任何疑问,我们很乐意在您需要时加入该代码。

以下是我的_navbar.html.erb(这是基金会网站' s顶栏示例中的c / p):

<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文件(在删除turbolinks的引用之后):

// 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(删除turbolinks后):

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

2 个答案:

答案 0 :(得分:2)

尝试在结束body标记之前移动它:

<%= javascript_include_tag "application" 'data-turbolinks-track' => true %>

答案 1 :(得分:1)

运行rails g foundation:install并允许命令覆盖主应用程序ERB文件后,您最终会在javascript_include_tag中找到turbolinks代码。

在您的application.html.erb中,更改此内容...

<%= javascript_include_tag "application" 'data-turbolinks-track' => true %>

到此......

<%= javascript_include_tag "application" %>

这个单行代码更改应该修复它。它对我有用。