railsに、AdminLTEを導入する

1. node.jsをインストールする
$ brew install nodebrew
$ nodebrew install-binary latest

[error]
Fetching: https://nodejs.org/dist/v7.4.0/node-v7.4.0-darwin-x64.tar.gz
Warning: Failed to create the file
Warning: /Users/○○/.nodebrew/src/v7.4.0/node-v7.4.0-darwin-x64.tar.
Warning: gz: No such file or directory

※上記ディレクトリが無いというエラーが出た場合、以下のディレクトリを作成後、再度実施。
$ mkdir ~/.nodebrew
$ mkdir ~/.nodebrew/src


2. pathをとおす
$ vi ~/.bash_profile
$ export PATH=$PATH:/Users/xxxxx/.nodebrew/node/v7.4.0/bin ←~/.bash_profileに追記して、pathをとおす
$ source ~/.bash_profile


3. bower で AdminLTE をインストールする
$ npm install bower -g

①Gemfile に以下を記述し bundle install を実行
$ gem 'bower-rails'
②bower-railsの初期設定
$ rails g bower_rails:initialize
⇛Bowerfile が作成されるので以下を記述し、AdminLTE をインストールする。
  asset 'admin-lte'
$ rake bower:install


4. font-awesomeを導入する
  gem 'font-awesome-rails'
$ bundle install


5. cssを読み込む設定を入れる
app/assets/stylesheets/application.css.scss内に、以下を記載する。
  *= require admin-lte/bootstrap/css/bootstrap
  *= require admin-lte/dist/css/AdminLTE
  *= require admin-lte/dist/css/skins/skin-blue
  *= require font-awesome


6. jsを読み込む設定を入れる
app/assets/javascripts/application.js内に、以下を記載する。
  //= require admin-lte/bootstrap/js/bootstrap
  //= require admin-lte/dist/js/app.js


7. .gitignoreにbowerのフォルダを追加しておく
app/assets/javascripts/application.js内に、以下を記載する。
$ echo /vendor/assets/bower_components >> .gitignore


参考URL:
http://qiita.com/niku4i/items/99ee439031330269d49a
https://miningoo.com/785

railsプロジェクトを作成する

1. railsプロジェクト用のディレクトリを作成する
$ mkdir rails-project
$ cd rails-project


2. GemFileを作成する
$ bundle init


3. GemFileを編集して、gemのインストールを行う

gem 'rails'のコメントアウトを外す。

$ vi Gemfile
  1 source 'https://rubygems.org'
  2
  3 gem 'rails'

$ bundle install --path vendor/bundle --jobs=4

※vendor/bundleディレクトリにgemをインストールする。

4. railsプロジェクトを作成する
$ bundle exec rails new . --database=mysql --skip-turbolinks --skip-test

※データベースはMySQLを指定。
※turbolinksを使用しない。
※test-unitを使用しない。

→下記、mysql2のインストールでエラーが発生したが、Xcodeをアップデートしたら解消した。

[mysql2のインストールエラー]
An error occurred while installing mysql2 (0.4.5), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.4.5'` succeeds before bundling.
         run  bundle exec spring binstub --all
Could not find gem 'mysql2 (< 0.5, >= 0.3.18)' in any of the gem sources listed in your Gemfile or available on this machine.
[エラー解消方法]
$ xcode-select --install
$ gem install mysql2 -v '0.4.5'

※参考にした記事:
qiita.com

5. 必要なgemをインストールする
$ vi Gemfile
$ bundle

※良さそうなgemを探す参考記事:
qiita.com

6. .gitignoreに'/vendor/bundle'を追記する
$ vi .gitignore
 /vendor/bundle


6. railsサーバーを立ち上げて、アクセスしてみる
$ rails s

http://localhost:3000/に初回アクセスすると下記のエラーが発生するので、DBを作成する。
 ActiveRecord::NoDatabaseError (Unknown database 'rails-project_development'):

$ rake db:create


6. railsサーバーを立ち上げて、アクセスしてみる

http://localhost:3000/にアクセスできればOK!!

【環境構築】MacでRails開発環境を構築する

1. Homebrewをインストールする

brewコマンドを使ってパッケージ管理システムである「Homebrew」をインストールする。

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

※「Homebrew」がインストール時に以下のエラーが表示されたら、以下のコマンドを実行して、Command Line Tools for Xcodeをインストールする。

xcode-select: note: install requested for command line developer tools
xcode-select --install

brew.sh


2. rbenvをインストールする

「rbenv」は、Rubyのバージョン管理を行ってくれるツールです。
brewコマンドを使って、「rbenv」をインストールします。

brew update
brew install rbenv ruby-build

vi ~/.bash_profile
export PATH="$HOME/.rbenv/shims:$PATH" ←~/.bash_profileに追記して、pathをとおす
source ~/.bash_profile


3. rubyをインストールする
rbenv install -l ←インストール可能な最新のrubyバージョンをリストで確認します
rbenv install 2.4.0 ←最新のバージョンをインストールします
rbenv rehash
rbenv global 2.4.0
ruby -v


4. MySQLをインストールする
brew install mysql

vi ~/.bash_profile
export PATH="/usr/local/bin/mysql:$PATH" ←~/.bash_profileに追記して、pathをとおす
source ~/.bash_profile


5. Ruby on Railsをインストールする
gem install bundler
gem install rails
rbenv rehash
rails -v


お疲れ様でした!!
Ruby on Rails開発環境の構築は以上です。
この後は下記コマンドを実行して、railsプロジェクトを作成していきます。

rails new アプリ名