LoginSignup
1
1

More than 5 years have passed since last update.

学習ノート ~ RubyOnRails5

Last updated at Posted at 2018-06-18

学習スケジュール(目次)

1. 環境設定
2. Ruby on Railsの基本
3. Scaffold機能を使ってみる
4. ビュー
5. モデル
6. コントローラー
7. ルーティング
8. CoffeeScript, SCSS
9. 実習(サンプルアプリ作成)


1. 環境設定

下記のリンクを参考に環境設定を行います。
ローカル開発環境の構築 [macOS編]
https://dotinstall.com/lessons/basic_localdev_mac_v2

Ruby on Rails 5入門 "#02 動作確認をしてみよう (02:47)"まで
https://dotinstall.com/lessons/basic_rails_v3


2. Ruby on Railsの基本 (作成中)

新規アプリ作成コマンド

> rails new helloRails

自動生成されるアプリのフォルダー構成

.
|-- .gitignore
|-- Gemfile
|-- Gemfile.lock
|-- README.md
|-- Rakefile
|-- app
|   |-- assets
|   |   |-- config
|   |   |   `-- manifest.js
|   |   |-- images
|   |   |   `-- .keep
|   |   |-- javascripts
|   |   |   |-- application.js
|   |   |   |-- cable.js
|   |   |   `-- channels
|   |   |       `-- .keep
|   |   `-- stylesheets
|   |       `-- application.css
|   |-- channels
|   |   `-- application_cable
|   |       |-- channel.rb
|   |       `-- connection.rb
|   |-- controllers
|   |   |-- application_controller.rb
|   |   `-- concerns
|   |       `-- .keep
|   |-- helpers
|   |   `-- application_helper.rb
|   |-- jobs
|   |   `-- application_job.rb
|   |-- mailers
|   |   `-- application_mailer.rb
|   |-- models
|   |   |-- application_record.rb
|   |   `-- concerns
|   |       `-- .keep
|   `-- views
|       `-- layouts
|           |-- application.html.erb
|           |-- mailer.html.erb
|           `-- mailer.text.erb
|-- bin
|   |-- bundle
|   |-- rails
|   |-- rake
|   |-- setup
|   |-- spring
|   `-- update
|-- config
|   |-- application.rb
|   |-- boot.rb
|   |-- cable.yml
|   |-- database.yml
|   |-- environment.rb
|   |-- environments
|   |   |-- development.rb
|   |   |-- production.rb
|   |   `-- test.rb
|   |-- initializers
|   |   |-- application_controller_renderer.rb
|   |   |-- assets.rb
|   |   |-- backtrace_silencers.rb
|   |   |-- cookies_serializer.rb
|   |   |-- filter_parameter_logging.rb
|   |   |-- inflections.rb
|   |   |-- mime_types.rb
|   |   |-- new_framework_defaults.rb
|   |   |-- session_store.rb
|   |   `-- wrap_parameters.rb
|   |-- locales
|   |   `-- en.yml
|   |-- puma.rb
|   |-- routes.rb
|   |-- secrets.yml
|   `-- spring.rb
|-- config.ru
|-- db
|   `-- seeds.rb
|-- lib
|   |-- assets
|   |   `-- .keep
|   `-- tasks
|       `-- .keep
|-- log
|   `-- .keep
|-- public
|   |-- 404.html
|   |-- 422.html
|   |-- 500.html
|   |-- apple-touch-icon-precomposed.png
|   |-- apple-touch-icon.png
|   |-- favicon.ico
|   `-- robots.txt
|-- test
|   |-- controllers
|   |   `-- .keep
|   |-- fixtures
|   |   |-- .keep
|   |   `-- files
|   |       `-- .keep
|   |-- helpers
|   |   `-- .keep
|   |-- integration
|   |   `-- .keep
|   |-- mailers
|   |   `-- .keep
|   |-- models
|   |   `-- .keep
|   `-- test_helper.rb
|-- tmp
|   |-- .keep
|   `-- cache
|       `-- assets
`-- vendor
    `-- assets
        |-- javascripts
        |   `-- .keep
        `-- stylesheets
            `-- .keep

よく使うコマンド

sqlite関連コマンド

  • 接続
sqlite3 db/development.sqlite3
  • 切断(スキーマ変更などある場合使う。一旦切断して再接続)
.exit
  • スキーマ確認
.schema テーブル名
  • SELECT表示モード
//タイトル表示 
.mode header 

//みやすい表示
.mode line
  • 他のコマンドはこちら

Rails DB関連コマンド

  • モデル生成
rails generate model agreementHistory
  • モデルがすでに存在する場合のscaffold
rails generate scaffold_controller users
  • マイグレーション
//migration
rails db:migrate  

//リセットしてからmigration
rails db:migrate:reset  

//バージョン指定
rails db:migrate VERSION=20180427212228 
  • データ関連
//スキーマから再構築
db:schema:load 

//データ挿入
rails db:seed   

vagrant関連

//vagrant 接続
vagrant ssh

//起動
vagrant up

//ステータス
vagrant status

//終了
vagrant halt

Railsサーバー起動、停止

//プロジェクトフォルダーへ
cd WORK/作業ディレクトリ

//Railsサーバー起動
rails server -b 192.168.33.10 -d

//サーバープロセス番号を確認
cat tmp/pids/server.pid

//サーバーを停止
kill -9 13432(プロセス番号)

//ログ確認
tail log/development.log

確認してみる

> http://localhost:3000

(作成中..)

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