Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Ruby on Rails

Execute SQL on Rails console

result = ActiveRecord::Base.connection.execute("SELECT * FROM users")

Good_job Postgres Threads

In database.yaml

  pool: <%= $PROGRAM_NAME.include?("good_job") ? ENV.fetch("GOOD_JOB_MAX_THREADS", 5).to_i + 3 : ENV.fetch("RAILS_MAX_THREADS", 5).to_i %>

Dependencies on Ubuntu with MySQL

apt install curl ufw fail2ban git-core apt-transport-https ca-certificates \
            software-properties-common python3-pip virtualenv python3-setuptools \
            vnstat screen htop tree yarn nodejs redis-server vim gnupg2 imagemagick \
            libmagickwand-dev zlib1g-dev  build-essential  libssl-dev \
            libreadline-dev  libyaml-dev  libxml2-dev  libxslt1-dev  \
            libcurl4-openssl-dev libffi-dev dirmngr gnupg autoconf bison \
            libreadline6-dev libncurses5-dev libmysqlclient-dev mysql-server-5.7 \
            rbenv ruby2.3 ruby2.3-dev bundler python3-certbot-apache \

New list of dependencies

  • libmagic-dev for ruby-filemagic
  • libvips for ..
apt install libmagic-dev \
            libvips

pip3 install -U numpy pandas

For PG gem

apt-get install libpq-dev

Ruby with rbenv

DO NOT USE apt package.

git clone https://github.com/rbenv/rbenv.git ~/.rbenv && echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install 1.2.3 && rbenv local 1.2.3

Edit credentials

EDITOR="vim" bin/rails credentials:edit --environment staging

Check the result with: Rails.configuration.database_configuration on the Rails console.

Generate Master Key

bundle exec rails secret | cut -c-32

Secret_key_base

You need to set one for production environments. Just do this and it will be created.

EDITOR=vim bundle exec rails edit:credentials

constants.rb