1
2

More than 3 years have passed since last update.

Ruby on Railsで新規アプリケーションを立ち上げる自称最速手順(github連携)

Last updated at Posted at 2020-03-22

目的

新規のアプリケーションを作成する際、
毎回「あれ?次どうするんだっけ?」ってなって調べている時間がムダなので、
最低限のものを最速で作る手順を残しておきます。
細かいことにこだわらず、とにかくサッと作成したいときに参考にしてください。
githubにも連携します。

前提

マークアップはhaml,scssを使用
リセットcssはyui3を使用
ローカルでビューファイルを開くところまでを記載

1.Railsのバージョン確認

ターミナル
% cd ~
% ruby -v

バージョンの変更が必要な場合は以下のコマンドを実行
(--version=以降は適宜指定してください。)

ターミナル
% gem install rails --version="5.0.7.2"
% rbenv rehash

2.アプリケーションの作成

ターミナル
% cd
% cd projects
% rails _5.0.7.2_ new <アプリケーション名> -d mysql
% cd <アプリケーション名>
% rails db:create
% git init

3.GitHubとの連携

GitHub DesktopのCurrent Repositoryタブ
→Add
→Add Existing Repository
→Chooseから ~ projects/<アプリケーション名>を選択
→Add Repository
→コミット名をinitial commitとし、Commit to master
→Publish repository
→Publish repository
→GitHubのリポジトリに反映していればOK

4.ルーティング/コントローラー/ビュー の設定

routes.rb
Rails.application.routes.draw do
  root to: 'posts#index'
end
ターミナル
% rails g controller posts
posts_controller.rb
class PostsController < ApplicationController
  def index    
  end
end
Gemfile
#最下部に追加
gem "haml-rails"
ターミナル
% bundle install

app/assets/stylesheetsフォルダ内で以下を実行

application.cssを削除する
application.scssを新規作成する
posts.scssのファイル名を _posts.scssに変更する
_reset.scssを新規作成する
ダウンロード/yui3-3.18.1/src/cssreset/css/cssreset.cssのコードを_reset.scssに貼り付ける

application.scss
@import "reset";
@import "posts";

app/views/postsフォルダ内で以下を実行

index.html.hamlを新規作成

index.html.haml
hello

確認

ターミナル
% rails s

ローカルでhelloと表示されれば完了

以上です。
最後まで読んでいただきありがとうございました。

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