Record of Pythonist reincarnated in Ruby on Rails

at first

Until now, most of the development was in PHP or Python, but due to various reasons, I decided to work on a Ruby on Rails project. I am studying Ruby on Rails while comparing it with Python, but I would like to leave an article that I referred to at that time. The contents will be updated from time to time.

table of contents

environment

About Ruby itself

In Python, I used the following environment.

* pyenv(Python version control)
* pip(Default Package management)
* pipenv(Virtual environment construction+Package management)

Ruby corresponds to each (in fact, many tools around Python were inspired by Ruby's tools, so this should be the origin).

* rbenv(Ruby version control)
* gem(Default Package management:However, in Ruby, Package is called Gem.)
* bundler(Virtual environment construction + Gem management)

is. Gem is like a Package in Python. A typical Ruby project uses bundler

mkdir PROJECT_DIR
cd PROJECT_DIR

rbenv local 2.6.5 #pipenv install 3.8.It is the same as 0
gem install bundler

bundler init #This will gemfile, Gemfile.A lock is created. Same as pipenv init

vi Gemfile #Describe the required libraries in the Gemfile
bundler install --path vendor/bundler #Vendor the libraries described in Gemfile/Install under bundler
bundler exec COMMAND #Command corresponding to pipenv run COMMAND

It seems to create an environment as.

Pipenv and Bundler are roughly the same, with the following minor differences:

Whether or not the --path option should be specified during the bundle install seems to be a religious war, and think again if there really is a need to add --path vendor / bundle during the bundle install. Let's see was helpful. (I don't want to pollute the System, so I decided to vendor / bundle)

Rails environment construction

Rails is a web development framework for Ruby. I thought it was like Flask, but it's more like Django's counterpart.

Rails is an integrated web development environment and includes bundler. By the way, Bundler and Bundle are the same. According to the official Bundler documentation, Rails includes Bundler.

Rails comes with baked in support with bundler. Bundler official documentation

Installing Rails with Bundler

gem install rails
rails new APP_DIR
cd APP_DIR
bundler install

Seems to be good.

However, Rails is installed in System at this time. I want to keep the System RubyGem as clean as possible, so do the following:

mkdir APP_DIR
cd APP_DIR
bundler init
vi Gemfile #Now add rails to Gemfile
bundler install --path vendor/bundle #BUNDLE above_If you have set PATH`--path`No options required
bundler exec rails install -B -d mysql
# -B: Don't do bundler install again at rails new
# -d Use mysql as DB. (Default is sqlite)

#At this point you will be asked if you want to Overwirte the existing Gemfile, so Y

Reference: Summary of procedure for creating a new Rails project

Doing Ruby on Rails

Recommended Posts

Record of Pythonist reincarnated in Ruby on Rails
Summary of Differences Between Ruby on Rails and Django ~ Basics ~
[Ruby on Rails] Display and pinning of GoolgeMAP using Google API
A record of the time it took to deploy mysql on Cloud9 + Rails
A well-prepared record of data analysis in Python
Rock-paper-scissors in Ruby
Difference between Ruby and Python in terms of variables
Difference in results depending on the argument of multiprocess.Process