LoginSignup
51
52

More than 5 years have passed since last update.

RailsでTwitter Bootstrapを使う

Posted at

昨日やったRails4初期設定の後、Twitter Bootstrapの設定をちゃんとやらなかったら、地味にハマった・・

どうも幾つかGemが足りなかったらしい。。
ここらへん追加して、もう一度 bundle install する。

# Bootstrap
gem 'less-rails'
gem 'therubyracer'
gem 'twitter-bootstrap-rails', '~> 2.2.8'
gem 'font-awesome-rails'
gem 'bootstrap-sass', '2.3.2.0'

Hamlでrails generateされるように指定

config/application.rb
config.generators do |g|
  g.template_engine :haml
end

Bootstrapを使えるようにする

$ bundle exec rails g bootstrap:install less

Bootstrapのレイアウトを作る

application layout をレスポンシブ対応のレイアウトにする。

$ bundle exec rails g bootstrap:layout application fluid

scaffoldしたリソースにBootstrapを適用

$ bundle exec rails g scaffold Post title:string content:text
$ bundle exec rake db:migrate
$ bundle exec rails g bootstrap:themed Posts -f

scaffoldしたviewを上書きさせるために-fをつける。
付けなくても一個ずつyで上書き確認でもOK


参考:twitter-bootstrap-rails/README.md at master · seyhunak/twitter-bootstrap-rails

やはり本家を見ないとダメですね・・・

51
52
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
52