Skip to main content

Ruby on Rails - Commands

# install ruby on rails
gem install rails

bundle install

rails new first-api --api --database=postgresql

rails generate resource User username:string password_digest:string

rails g resource Post title content user_id:integer

bundle install

EDITOR="code --wait" rails credentials:edit

rails g serializer user

rails db:create

rails db:migrate

rails s

rails routes

rails c # enter to the rails console

# add field
rails generate migration add_total_investment_usd_to_programs total_investment_usd:float
rails generate migration quota_type_to_payments quota_type:int

# add references
rails generate migration add_pay_method_ref_to_payments pay_method:references

#---------

gem install bundler

bundle update

# pg issue
sudo apt-get -y install libpq-dev

#-----------

# The rails db:reset task will drop the database and set it up again. This is functionally equivalent to rails db:drop db:setup.
# psql -h localhost -p 3200 -U postgres < backup_date-15-04-2022_00-00-00-production.sql
#----------------------------------------------------------

rails g model PayMethod name type:integer account_number:integer account_type

rails g serializer PayMethod name type account_number account_type

rails db:migrate

rails db:seed

# to update cron tab file
bundle exec whenever --update-crontab --set environment='development'
bundle exec whenever --update-crontab

rails g task batch update_usd_rate

# to test task
rails batch:update_usd_rate

# list crontabs
crontab -l

# Ubuntu cron tab file location:
# /var/spool/cron/crontabs/

#
sudo service cron reload
sudo /etc/init.d/cron start
sudo /etc/init.d/cron stop
sudo /etc/init.d/cron status