* RailsでMongoDBを使用する為の環境設定メモ(Windows) [#if99318a] #setlinebreak(on) #contents -- 関連 --- [[RailsでMongoDBを使用する]] --- [[MongoDB]] ** MongoDB のインストール [#yc218367] https://www.mongodb.org/ ** mongodb用のデータディレクトリ作成 [#q3b941da] #myterm2(){{ mkdir c:\data mkdir c:\data\mongo }} ** mongodbにdbを作成 [#g3b90e62] #myterm2(){{ mongod --dbpath=c:\data\mongo > use example > use example_development > use example_test > exit }} ** Ruby、Rails のインストール [#y1b9f5d5] *** rubyインストール [#f029ac20] http://rubyinstaller.org/downloads/ インストール先 ... c:\ruby22 *** devkitインストール [#a28d4b08] http://rubyinstaller.org/downloads/ インストール先 ... c:\devkit コマンドプロンプトから以下を実行 #myterm2(){{ c\devkit\devkitvars c\devkit\dk.rb init c\devkit\dk.rb install }}} *** rubygems のアップデート コマンドプロンプトから以下を実行 #myterm2(){{ gem update --system }} *** bundler のインストール [#ec4348a4] ※gemの一括インストール用 コマンドプロンプトから以下を実行 #myterm2(){{ gem install bundler bundle install --path vendor/bundle }} *** rails のインストール [#le3c9b35] コマンドプロンプトから以下を実行 #myterm2(){{ gem install rails --version="~> 4.2.3" --no-ri --no-rdoc }} *** rails プロジェクトの作成 [#gcb4d191] プロジェクトの作成 #myterm2(){{ rails new example --skip-active-record --skip-bundle }} GemFileに追記 #mycode2(){{ gem 'mongoid', '~> 4.0.0' }} gem 一括インストール #myterm2(){{ bundle install }} mongoidの設定ファイル作成 #myterm2(){{ rails g mongoid:config }} *** うまくいかない時 [#mb75304a] #html(<div style="margin-left:10px;padding:0 10px 10px 10px;border:1px solid #666;">) 個別インストール #myterm2(){{ gem install mongoid --version="~>4.0.0" }} #html(</div>) *** coffeeScript が TypeError になる場合 [#b2885abf] #html(<div style="margin-left:10px;padding:0 10px 10px 10px;border:1px solid #666;">) coffee-script-source をバージョン指定してインストールする (1) Gemfileに追加 #myterm2(){{ gem 'coffee-script-source', '1.8.0' }} (2) 再度Gemインストール #myterm2(){{ bundle install bundle update coffee-script-source }} #html(</div>) *** 動作確認用の処理を作成 [#g2e26d2a] #myterm2(){{ rails g scaffold book name author price:integer autor notes:text }} *** Rails起動 [#w478fa16] #myterm2(){{ rails s }} *** 動作確認 [#hb68c194] http://localhost:3000/books *** 動作確認用の処理を削除 [#j42fd314] #myterm2(){{ rails destroy scaffold book }}