简体   繁体   English

使用Rails安装Twitter Bootstrap

[英]Installing twitter bootstrap with Rails

I am trying to install on an existing project Twitter Bootstrap 我正在尝试在现有项目Twitter Bootstrap上安装

I tried to do that, following this : 我想这样做,下面这个

group :assets do
  gem 'bootstrap-sass-rails'
end

and I got that : 我明白了:

Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    bootstrap-sass-rails (>= 0) java depends on
      actionpack (~> 3.1.0) java

    rails (= 2.3.14) java depends on
      actionpack (2.3.14)

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    bootstrap-sass-rails (>= 0) java depends on
      rails (~> 3.1.3) java

    rails (2.3.14)

Knowing that when I run rails -v, I get rails 3.2.12. 知道当我运行rails -v时,我得到了rails 3.2.12。 So, following the doc, I tried this 所以,按照文档,我尝试了

gem install bootstrap-sass-rails gem install bootstrap-sass-rails安装

I am told that the gem is successfully installed but I don't see any new file in my app folder. 有人告诉我gem已成功安装,但我的应用程序文件夹中没有看到任何新文件。 By the way, I tried to add in one of my stylesheet this 顺便说一句,我试图添加我的样式表之一

**/*
 *= require twitter/bootstrap
 */
**

But no bootstrap css seems to be called on my layouts. 但是似乎没有在我的布局上调用bootstrap css。 Could someone help ? 有人可以帮忙吗? Is this the right way to install Bootstrap ? 这是安装Bootstrap的正确方法吗?

update : I have just noticed that in the gem file I have : gem "rails", "2.3.14" 更新:我刚刚注意到在gem文件中,我有:gem“ rails”,“ 2.3.14”

For Rails 3: 对于Rails 3:

I have bootstrap and fontawesome installed. 我安装了bootstrap和fontawesome。 Here's my Gemfile: 这是我的Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.12'

# ...

# jQuery
gem 'jquery-rails'

# Twitter Bootstrap
gem 'bootstrap-sass'
gem 'font-awesome-sass-rails'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
end

As you can see, I use a different gem for bootstrap. 如您所见,我为引导程序使用了另一个gem。 After editing Gemfile, just type bundle (or maybe bundle update is necessary) 编辑Gemfile后,只需键入bundle (或者可能需要bundle update


This is my application.css.scss (under app/assets/stylesheets/): 这是我的application.css.scss(在app / assets / stylesheets /下):

@import "bootstrap";
@import "font-awesome";
body { padding-top: 60px; }
@import "bootstrap-responsive";

And application.js (under app/assets/javascripts/): 和application.js(在app / assets / javascripts /下):

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .

I have had issues following the " http://railscasts.com/episodes/328-twitter-bootstrap-basics " as nothing I did looks as good as the output of the cast until I notice "Update February 6, 2013: The setup process for twitter-bootstrap-rails has changed since this episode. Check out the README for details on how to set it up." 在“ http://railscasts.com/episodes/328-twitter-bootstrap-basics ”之后,我遇到了问题,因为我所做的一切都不如演员表的输出,直到我注意到“ 2013年2月6日更新:安装自本集以来,twitter-bootstrap-rails的过程已更改。请查看自述文件以获取有关如何进行设置的详细信息。”

So I followed to https://github.com/seyhunak/twitter-bootstrap-rails and make the following installation steps and it works for me now: 因此,我遵循了https://github.com/seyhunak/twitter-bootstrap-rails并进行以下安装步骤,它现在对我有用:

  1. Create a new rails 3.2.x app, 创建一个新的Rails 3.2.x应用程序,
    (if you rvm fan, work with rvm then) (如果您是rvm风扇,请与rvm一起使用)
    rails new Store rails新店

  2. Edit Gemfile, and the following: 编辑Gemfile,然后执行以下操作:
    gem "therubyracer" 宝石“ therubyracer”
    gem "less-rails" 宝石“少铁”

    gem 'twitter-bootstrap-rails'# * *doest work for me, so I need pull from the source as follow gem'twitter-bootstrap-rails'# *对我来说很有效,因此我需要从源代码中按以下步骤进行操作

    gem 'twitter-bootstrap-rails', :git => ' https://github.com/seyhunak/twitter-bootstrap-rails.git ' gem'twitter-bootstrap-rails',:git =>' https://github.com/seyhunak/twitter-bootstrap-rails.git '

  3. run bundle install 运行捆绑安装

  4. Install bootstrap less, rails generate bootstrap:install less 少安装bootstrap,rails生成bootstrap:少安装

  5. Install bootstrap static, 静态安装bootstrap,
    rails generate bootstrap:install static Rails生成引导程序:安装静态

  6. Copied and pasted the following lines into your "bootstrap_and_overrides.less", 将以下行复制并粘贴到您的“ bootstrap_and_overrides.less”中,
    @import "twitter/bootstrap/reset.less"; @import“ twitter / bootstrap / reset.less”;
    @import "twitter/bootstrap/variables.less"; @import“ twitter / bootstrap / variables.less”;
    @import "twitter/bootstrap/mixins.less"; @import“ twitter / bootstrap / mixins.less”;
    @import "twitter/bootstrap/scaffolding.less"; @import“ twitter / bootstrap / scaffolding.less”;
    @import "twitter/bootstrap/grid.less"; @import“ twitter / bootstrap / grid.less”;
    @import "twitter/bootstrap/layouts.less"; @import“ twitter / bootstrap / layouts.less”;
    @import "twitter/bootstrap/type.less"; @import“ twitter / bootstrap / type.less”;
    @import "twitter/bootstrap/forms.less"; @import“ twitter / bootstrap / forms.less”;
    @import "twitter/bootstrap/wells.less"; @import“ twitter / bootstrap / wells.less”;
    @import "twitter/bootstrap/component-animations.less"; @import“ twitter / bootstrap / component-animations.less”;
    @import "twitter/bootstrap/buttons.less"; @import“ twitter / bootstrap / buttons.less”;
    @import "twitter/bootstrap/close.less"; @import“ twitter / bootstrap / close.less”;
    @import "twitter/bootstrap/navs.less"; @import“ twitter / bootstrap / navs.less”;
    @import "twitter/bootstrap/navbar.less"; @import“ twitter / bootstrap / navbar.less”;
    @import "twitter/bootstrap/labels-badges.less"; @import“ twitter / bootstrap / labels-badges.less”;
    @import "twitter/bootstrap/hero-unit.less"; @import“ twitter / bootstrap / hero-unit.less”;
    @import "twitter/bootstrap/utilities.less"; @import“ twitter / bootstrap / utilities.less”;
    @import "twitter/bootstrap/responsive"; @import“ twitter / bootstrap / response”;

  7. Generate the layout either fixed or fluid, your choice. 选择生成固定的布局还是固定的布局。

  8. Generate the model, 生成模型,
    rails g scaffold product name price:decimal --skip-stylesheets rails g scaffold产品名称:decimal --skip-stylesheets
    rake db:migrate 耙db:migrate
    rails g bootstrap:themed Products -f rails g bootstrap:主题产品-f

  9. run in development mode using WEBrick, 使用WEBrick在开发模式下运行
    rails s 滑轨

Hope that helps someone! 希望能对某人有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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