【问题标题】:Bootstrap Rails Not Working引导 Rails 不工作
【发布时间】:2017-04-20 15:16:58
【问题描述】:

大家好,我已经为我的应用程序安装了引导程序,但它运行得并不好。这是我的 application.scss 文件

@import "bootstrap-sprockets";
@import "bootstrap";

这是我的 application.rb 文件:

<!DOCTYPE html>
<html>
  <head>
    <title>BootstrapApp</title>

    <%= stylesheet_link_tag    'default', media: 'all', 'data-turbolinks-track' => true%>
    <%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
  </head>

  <body>
        <%= yield %>
  </body>
</html>

application.js 文件:

// 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 any plugin's vendor/assets/javascripts directory 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. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets 
//= require turbolinks
//= require_tree .

最后是我的宝石文件:

source 'http://rubygems.org'

gem 'bootstrap-sass', '~> 3.3.5'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

这是我在尝试向我的网页添加导航栏时得到的结果:

【问题讨论】:

  • 您是否遇到任何错误?如果是,请发布错误消息?
  • 不,我没有收到任何错误消息,只是当我转到索引页面时,文本只是普通的 html,没有任何引导程序,添加了引导程序,我应该能够看到文本的变化没有?
  • 从 application.scss/css 中删除引导链轮。
  • @Aaron 嗯,奇怪。您是否尝试过任何特定于引导程序的样式来确认?如果可能,您可以链接到屏幕截图吗?据我所知,我没有发现任何错误。
  • @ArunKumar 我添加了我的显示屏幕截图。如您所知,没有应用引导程序

标签: ruby-on-rails twitter-bootstrap


【解决方案1】:

问题是您不需要application.scssapplication.js

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true%>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

如果您收到Object does not support the property or method 错误,请使用“coffee-script-source”的最新 gem(如 1.10.0)- 1.9.x 版以外的任何版本。

将以下行添加到Gemfile,运行bundle install并重新启动服务器。

gem 'coffee-script-source', '~> 1.11', '>= 1.11.1'

【讨论】:

  • 仍然...安装后。它给了我同样的错误:(
  • @Aaron 您应该尝试this 问题的第一个答案。它有点脏,但应该可以。
【解决方案2】:

我终于让它工作了。 this link 为我提供了我的解决方案。感谢所有在这篇文章中帮助过我的人,非常感谢和很棒的学习体验:)

【讨论】:

    猜你喜欢
    • 2018-02-18
    • 2013-11-26
    • 2014-11-02
    • 1970-01-01
    • 2012-03-10
    • 2018-03-07
    • 2016-05-11
    • 1970-01-01
    相关资源
    最近更新 更多