LoginSignup
0
0

More than 5 years have passed since last update.

Ruby On Rails 4 にmysqlを利用するプロジェクトをさらっと作成する手順

Last updated at Posted at 2016-04-07

速攻でRuby On Rails + mysqlプロジェクトを作って試したい、という時の手順です。
お試し環境構築を作る手順なので本番用の堅い環境を作る場合は他を御覧ください。

前提

  • ユーザーはroot。
  • myprojectという名のプロジェクト名

動作環境

  • CentOS 6.7
  • ruby 2.2 インストール済
  • Ruby On Rails 4.2 インストール済
  • mysql 5.5 インストール済

手順

早速プロジェクト作成。-d オプションでmysqlを指定。

rails new myproject -d mysql

therubyracerを有効にする。Gemfileを開いて以下のコメントアウトをアンコメントする。

vi myproject/Gemfile
myproject/Gemfile
# gem 'therubyracer', platforms: :ruby

rubyracerをインストール

cd myproject
bundle install

mysqlにツナグためにID,パスワードを指定。

vi config/database.yml
config/database.yml

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: ここにmysqlの管理者ユーザーID
  password: ここにmysqlの管理者パスワード
  socket: /var/lib/mysql/mysql.sock

データベース生成

bundle exec rake db:create

実行していつものWelcome aboard画面がでることを確認。

rails s

scaffold、DB更新の例

rails generate scaffold user username:string password:string 
rake db:migrate

文献

Ruby on RailsでMySQLを使用する際に必要な作業手順

Ruby on Rails 4 アプリケーションプログラミング(書籍)

0
0
0

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
0
0