2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby on Rails [学習記録-第1章-]

Last updated at Posted at 2019-06-18

アプリケーション開発

  • 本章からアプリケーション開発において必要となる知識を整理、記録していく。

ターミナルコマンド

$ cd    #ディレクトリの移動
$ pwd   #ディレクトリの参照
$ rails s #テストサーバー起動、テストサーバー終了は"controll + c"

新規アプリケーションの作成

  • Railsで新規アプリケーションを作る際は、rails newコマンドを使用する。
    コマンドはrails new アプリケーション名で実行する。オプションをつけるには- オプション名と追記する。
$ rails new アプリケーション名 - オプション名

$ rails _5.2.2.1_ new Application -d mysql
  • Rails newコマンドを実行するとアプリケーション名のディレクトリが作成される。
    場合によっては実行時に以下のエラーが表示される。
Installing mysql2 0.5.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/user_name/Programs/web/foobar-repo/vendor/bundle/ruby/2.5.1/gems/mysql2-0.5.2/ext/mysql2
/Users/user_name/.rbenv/versions/2.5.1/bin/ruby -r (以下略)
  • 上記エラーが表示された場合は以下のコマンドを入力する。
$ gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
$ cd ファイルの保存場所
$ bundle install
  • RailsでGemを追加するにはGemファイルgem 'gem名'と追記して、bundle installコマンド を実行する。
$ gem 'gem名'
$ bundle install

運用環境

運用環境は3種類ある。
ローカルでの開発では基本的にdevelopment環境と呼ばれる開発用の環境しか使用しない。

運用環境 概要
development 本番環境。アプリケーションをリリースする際に使用。
poduction 本番環境。アプリケーションをリリースする際に使用。
test テスト環境。アプリケーションの動作をテストする際に使用。

データベースの作成

  • データベースを作成するにはrake db:createコマンド を使用する。
    data base.ymlというファイルにもとづいてデータベースを作成される。
$ rake db:create
  • 以下のエラーが表示されることがある。
rake aborted!
Mysql2::Error::ConnectionError: Access denied for user 'root'@'localhost' (using password: NO)

データベースの確認

  • Sequel Proを使用すればデータベースの中身をわかりやすく視覚化できる。
    Sequel Pro
    接続時はソケット接続、名前:localhost、ユーザー名:rootで接続。
2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?