Adding twitter-bootstrap-rails with an existing ra

2020-06-03 00:13发布

问题:

I am trying to use twitter-bootstrap-rails with an existing rails application and getting the following error when i refreshed the page.

no such file to load -- less (in /app/assets/stylesheets/bootstrap_and_overrides.css.less)

Extracted source (around line #5):

2: <html>
3: <head>
4:   <title>Tracker</title>
5:   <%= stylesheet_link_tag    "application" %>
6:   <%= javascript_include_tag "application" %>
7:   <%= csrf_meta_tags %>
8: </head>

any idea what I am doing wrong? thanks

回答1:

In my case, only re-starting the rails server did not do the trick. I had to do following things to fix the problem.

1. I needed to install the missing gems first. I added following lines to my Gemfile :

  gem "therubyracer"
  gem "less-rails"

Then in console I ran:

bundle install

2. Lastly, I had to re-start my rails server.

After all these steps, twitter bootstrap started working with my rails app. Hope this helps someone who faces the same trouble that I did !



回答2:

In some case, you have not installed therubyracer.

add

#gem 'therubyracer' , '= 0.10.2'

to your Gemfile and

#bundle install

may resolve this problem. (In my case, I could not make the rubyracer 0.11.0, so I designated 0.10.2)

If you have not installed libv8, you have to exec

#gem install libv8 --version=3.11.8.3

or something like this before hand.



回答3:

I got it to work by replacing the stylesheet_link_tag to bootstrap_and_overrides. However, I am using devise for authentication and twitter-bootstrap-rails, I think is messes up the devise user model because none of the logout or sign in functions work.



回答4:

I was also able to get this to work by replacing 'application' with 'bootstrap_and_overrides' in the stylesheet_link_tag tag of the layout template, per sdurg4's suggestion.



回答5:

Using rails 3.2.13:

After I installed the 3 gems (therubyracer / less-rails / twitter-bootstrap-rails) I replaced this line *= require twitter/bootstrap with *= require bootstrap_and_overrides in application.css.

From the github updating guide:

This file imports Bootstrap and responsive styles for you (Responsive module is separated.) https://github.com/seyhunak/twitter-bootstrap-rails/wiki/Upgrading-Guide