我正在尝试让 bootstrap 使用 Rails,但到目前为止还没有运气。我按照此网站上的设置说明进行操作:https://github.com/twbs/bootstrap-sass
这是友好终端的内容:
Toms-MacBook-Air:GetItDone tomfinet$ bin/rails server
/Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.0.1/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
=> Booting WEBrick
=> Rails 4.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bootstrap-sass-3.3.6/lib/bootstrap-sass/engine.rb:11:in `block in <class:Engine>': uninitialized constant Sprockets::Rails::VERSION (NameError)
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `run'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `call'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/application.rb:215:in `initialize!'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/tomfinet/Documents/Rails Development/Projects/GetItDone/config/environment.rb:5:in `<top (required)>'
from /Users/tomfinet/Documents/Rails Development/Projects/GetItDone/config.ru:3:in `require'
from /Users/tomfinet/Documents/Rails Development/Projects/GetItDone/config.ru:3:in `block in <main>'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize'
from /Users/tomfinet/Documents/Rails Development/Projects/GetItDone/config.ru:in `new'
from /Users/tomfinet/Documents/Rails Development/Projects/GetItDone/config.ru:in `<main>'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:49:in `eval'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:49:in `new_from_string'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/server.rb:199:in `app'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/commands/server.rb:48:in `app'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.5/lib/rack/server.rb:314:in `wrapped_app'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/commands/server.rb:75:in `start'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/commands.rb:76:in `block in <top (required)>'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/commands.rb:71:in `tap'
from /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.0.1/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
这是我的 Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.1'
gem 'bcrypt-ruby', '~> 3.1.2'
gem 'sqlite3'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :development, :test do
gem 'rspec-rails', '~> 2.0'
gem "factory_girl_rails", "~> 4.0"
end
group :test do
gem 'capybara', '~> 2.1.0'
gem "capybara-email", "~> 2.2.0"
gem 'shoulda-matchers', '~> 2.4.0'
end
这是我的 application.scss 文件:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*/
@import "bootstrap";
div.alert {
border: 2px solid #aaa;
padding: 10px;
}
div.flash.success { border: 2px solid green; color: green; }
div.flash.error { border: 2px solid red; color: red; }
div.flash.notice { border: 2px solid blue; color: blue; }
.clear { clear: both; }
div.nav {
border-bottom: 1px solid #aaa;
margin-bottom: 20px;
padding: 10px 0 0 5px;
}
div.nav h1 {
float: left;
margin: 0 1em 0 0;
}
div.nav a { text-decoration: none !important; }
div.nav ul {
float: right;
list-style: none;
clear: right;
margin: 0 0 0 1em;
padding: 0;
}
div.nav ul li {
float: right;
}
div.nav ul li a {
display: block;
width: auto;
padding: 8px 10px 8px 10px;
background: #eee;
color: #aaa;
}
div.nav ul li a:hover {
background: #aaa;
color: #eee;
}
这是我的 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 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 turbolinks
//= require_tree .
//= require bootstrap-sprockets
所以有什么大惊小怪的?将 gem 添加到 gemfile 后(成功),我运行了捆绑安装。
非常感谢!
最佳答案
有一个issue带有旧版本的链轮 gem 。
我建议将以下行添加到您的 Gemfile
中:
gem 'sprockets-rails'
然后运行 bundle update sprockets-rails
并确保在 Gemfile.lock
中至少安装了 2.2
版本的 链轮
。
关于ruby-on-rails - 无法让 Bootstrap 与 Rails 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34283764/