简体   繁体   中英

Ruby on Rails importing bootstrap not found

Second Edit Thanks for all the helpful guidance, I was able to fix the error by rolling back my version of ruby. I had to make several other tweaks, but that was the main one, especially considering that I was following a tutorial.

Edit I am still unsuccessful after making the changes cjn suggested. I am getting this error:

 Static pages Home page should have the content 'Sample App'
 Failure/Error: visit '/static_pages/home'
 ActionView::Template::Error:
   couldn't find file 'jquery'
     (in /Users/me/rails_projects/sample_app/app/assets/javascripts/application.js:13)
 # ./app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb__1639650066512045899_2207712920'
 # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

----original post----

I am a novice in programming RoR. Currently I am going through the Michael Hartl, "Ruby on Rails Tutorial". I have been stuck on this problem for the past day or so.

In apps/assets/stylesheets I have a file called custom.css.scss. In this file i have one line:

@import "bootstrap";

however I am getting an error:

 Failure/Error: visit '/static_pages/about'
 ActionView::Template::Error:
   File to import not found or unreadable: bootstrap.
   Load paths:

     /Users/me/rails_projects/sample_app
     /Users/me/rails_projects/vendor/assets/stylesheets
     (in /Users/me/rails_projects/sample_app/app/assets/stylesheets/application.css)
 # (sass):15
 # ./app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__2871330256659661911_2185769240'
 # ./spec/requests/static_pages_spec.rb:39:in `block (3 levels) in <top (required)>'

In my Gemfile I have:

source 'https://rubygems.org'
ruby '2.1.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.5'
gem 'bootstrap-sass', '2.3.0.1'
gem 'sprockets', '2.12.1'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

I have looked at a lot of other posts on how to resolve similar issues, but to no avail.

Thanks in advance for any help!

Having spent the better part of a day figuring out this issue, I thought I'd share my solution. I too am following the Rails Tutorial by Hartl, and am following his advice by running everything in a cloud9 account.

The answer for me was to restart the server, however, this was not as easy as a simple ctrl+c as I had closed my terminal windows down entirely. As a result, I tried to issue "rails server -b $IP -p $PORT", however, I received a `bind': Address already in use .. ' error.

So here's how I solved it:

From terminal:

1.) $ lsof -i :8080 -> output will show PID of process occupying port 8080: "httpd 1234 ....'

2.) $ kill -9 1234

All errors gone and bootstrap working properly!

Lastly (and most importantly), it should be noted that during the tutorials, you should always issue "rails server -b $IP -p $PORT" and not "rails server". This is key.

The same issue occurred for me too, while i have gone through the tutorial of Michael Hartl( https://www.railstutorial.org/book/ ). But after i give bundle command by changing the order of gems in the gem file, this issue solved. The above issue on my guess, is mainly due to the c9 editor not refreshed properly with installed gem.

For me the solution was rename stylesheet file from css to scss

mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss

hope it help

For the formal answer that sounds like it worked...

Have you run through the github repository installation instructions? https://github.com/twbs/bootstrap-sass With Rails 3.1+, you do already have sass-rails so that's ok, but have you added @import "bootstrap-sprockets"; to your application.css file and //= require jquery & //= require bootstrap-sprockets to your application.js file?

Also, have you restarted your rails server since adding code to your .css or .js files?

If you are doing the Rails Tutorials and developing in cloud (c9), you should restart the workspace server. After that execute the rails test again and it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM