This year, I'm trying to challenge the Web little by little, so I'm messing with Rails, which seems to have the most references. For the time being, I've finished building a local environment and are trying various things with Rails new. I'm writing an article with the hope that I'd like to organize my mind once and make it into a template, and I'd be happy if you could point out any mistakes. I hope it will be helpful for those who are having trouble with Rails new.
terminal
Windows10
ruby 2.6.6
Rails 6.0.3.1
psql (PostgreSQL) 12.3
I will not write about environment construction, so please check if necessary. Change the database to PostgreSQL. And gems are basically put locally. It seems that either one is fine, but somehow it does.
Please create a directory appropriately.
terminal
C:\Users\user\sample_app> bundle init
Open the created Gemfile with an editor and add the following.
Gemfile
gem 'rails'//Comment out(#)Just remove
gem 'pg'//When changing to PostgreSQL
I'm not sure if I should specify the gem version, so I won't specify it for the time being.
terminal
bundle install --path vendor/bundle
--path vendor / bundle is specified when installing the gem locally. This seems to install the gem in vendor / bundle. It seems that --path vendor / bundle can be omitted by specifying only the first time.
terminal
bundle exec rails new . -d postgresql --skip-turbolinks --skip-test
bundle exec is attached when Rails is installed locally. After that, attach it to all rails commands. -d postgresql --skip-turbolinks --skip-test seems to have many other options, so check it out if necessary. There are many things I don't understand, so I'll just write what everyone is writing.
SQLShell(psql)
create role APPLICATION_NAME with createdb login password 'PASSWORD';
select * from pg_user;
Enter your user name (app name) in APPLICATION_NAME and any password in PASSWORD. Check if the role has been created with select * from pg_user ;.
Write the following in database.yml in the config folder.
database.yml
・
・
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: APPLICATION_NAME//add to(Username decided when creating the database)
password: PASSWORD//add to(Password decided when creating the database)
host: localhost//add to
・
・
After saving database.yml, update the database as well.
terminal
bundle exec rails db:migrate:reset
terminal
bundle exec rails s
In your browser http: // localhost: 3000 / If you access and the image is displayed, it is successful.
Recommended Posts