Bootstrap Rails 不工作 [英] Bootstrap Rails Not Working

查看:34
本文介绍了Bootstrap Rails 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我已经为我的应用程序安装了引导程序,但效果不佳.这是我的 application.scss 文件

Hello everyone I have installed bootstrap for my application, and it is not working out to well. Here is my application.scss file

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

这是我的 application.rb 文件:

Here is my application.rb file:

<!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 文件:

application.js file:

// 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 .

最后是我的 Gem 文件:

Finally here is my Gem File:

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]

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

Here is what I am getting when trying to add a navbar to my webpage:

推荐答案

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

The problem is you're not requiring application.scss and application.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 错误,请使用最新的 gem for "coffee-script-source"(如 1.10.0)- 1.9 以外的任何版本.X.

If you are getting the Object does not support the property or method error, then use the latest gem for "coffee-script-source" (like 1.10.0) - anything other than version 1.9.x.

Gemfile中加入下面一行,运行bundle install并重启服务器.

Add the following line to Gemfile, run bundle install and restart the server.

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

这篇关于Bootstrap Rails 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆