Rails app: using a gem vs. including source with Twitter Bootstrap

亡梦爱人 提交于 2019-11-28 04:47:31

I absolutely agree it's underwhelming to have the Bootstrap files sit outside your application.

I recommend the following workflow in this case:

  1. Clone the repo bootstrap-sass from Github or download the zipball. It's the official port of Bootstrap into Sass and it's kept updated by the same team.

  2. Copy only the Sass partials (the ones whose filename begins with an underscore) to app/vendor/assets/stylesheets. Javascript and images go into their respective directories under app/vendor/assets. That will remind you to stay away from editing those files while at the same time keeping your app's asset directories clean. And whenever you feel like taking a closer look at them, they will be right at hand.

  3. Copy bootstrap.scss to app/assets/stylesheets and tinker with those as much as you want. Be sure to turn off all the features you're not using, because carrying that stuff around will mean having a larger CSS file than you need.

  4. Customize your Boostrap variables and classes and load them after the Bootstrap files in your manifest, just like you would with a gem. For instance, let's say you put your own variables into _overrides.scss. Your application.css.scss would look like this:

    @import "bootstrap";
    @import "overrides";
    

That's it. That's what app/vendor/assets was made for!

i am relatively new to RoR and found there are several different ways to implement bootstrap. i tried the gem thomas-mcdonald / bootstrap-sass and got that to work great. but i wanted to get more in depth knowledge of what exactly the bootstrap files were doing and what the code looked like. the above answer was very helpful. i just wanted to add that this bootstrap 3 video proved to be very useful and worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!