LoginSignup
0
0

More than 3 years have passed since last update.

Rails新規アプリケーションの作り方

Posted at

GitHubでリポジトリつくる

Screen Shot 2020-11-20 at 21.55.27.png

localにcloneしてくる

$ git clone https://github.com/k-tetsuhiro/rails_docker_sample_3.git
& cd rails_docker_sample_3

bundleを初期化する

$ bundle init
Writing new Gemfile to /Users/kakuno/sandbox/rails_docker_sample_3/Gemfile

Gemfileができているので編集する

$ vi Gemfile
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "rails"

→ # gem "rails" のコメントアウトをはずす

bundle installして必要なものをインストールする

$ bundle install --path vendor/bundle
[DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set path 'vendor/bundle'`, and stop using this flag
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
--- 必要なgemがはいっていく... ---

Railsアプリケーションを作成する

$ bundle exec rails new . -B -d mysql --skip-turbolinks --skip-test
      exist
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
    conflict  Gemfile
Overwrite /Users/kakuno/sandbox/rails_docker_sample_3/Gemfile? (enter "h" for help) [Ynaqdhm]
--- ここで上書きしていいか聞かれるのでYを押して許可する ---

→最後になにかエラーメッセージが出てたらもう一度bundle installする

$ bundle install --path vendor/bundle

webpackerをinstallする

$ rails webpacker:install
      create  config/webpacker.yml
Copying webpack core config
      create  config/webpack
      create  config/webpack/development.js
--- 必要なものが入っていく ---

Railsサーバーを起動してみる

$ bundle exec rails s

→ようやくRails起動!! http://localhost:3000/ でアクセスできる(ただしまだMySQLなどの設定をしてないのでエラー画面になるはず)

gitで管理しないものを設定する

$ vi .gitignore

→無視するファイルを設定

.gitignore
# Created by https://www.toptal.com/developers/gitignore/api/rails
# Edit at https://www.toptal.com/developers/gitignore?templates=rails

### Rails ###
*.rbc
capybara-*.html
.rspec
/db/*.sqlite3
/db/*.sqlite3-journal
/db/*.sqlite3-[0-9]*
/public/system
/coverage/
/spec/tmp
*.orig
rerun.txt
pickle-email-*.html

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb
config/master.key

# Only include if you have production secrets in this file, which is no longer a Rails default
# config/secrets.yml

# dotenv, dotenv-rails
# TODO Comment out these rules if environment variables can be committed
.env
.env.*

## Environment normalization:
/.bundle
/vendor/bundle

# these should all be checked in to normalize the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# if using bower-rails ignore default bower_components path bower.json files
/vendor/assets/bower_components
*.bowerrc
bower.json

# Ignore pow environment settings
.powenv

# Ignore Byebug command history file.
.byebug_history

# Ignore node_modules
node_modules/

# Ignore precompiled javascript packs
/public/packs
/public/packs-test
/public/assets

# Ignore yarn files
/yarn-error.log
yarn-debug.log*
.yarn-integrity

# Ignore uploaded files in development
/storage/*
!/storage/.keep

# End of https://www.toptal.com/developers/gitignore/api/rails

コミットとプッシュ

$ git add *
$ git commit -m "first commit"
$ git push

→これでGitHubに更新される

Screen Shot 2020-11-20 at 22.24.27.png

番外編

rbenvを最新にする

railsを最新にする

[参考]
https://qiita.com/yuitnnn/items/b45bba658d86eabdbb26

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