Requires Ruby 3.1.6
Follow to setup rbenv and Ruby: https://gorails.com/setup/ubuntu/16.04#ruby-rbenv
- Install Node.js and Yarn repositories
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
- Install Ruby with
rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 3.1.6
rbenv global 3.1.6
ruby -v
https://stackoverflow.com/a/20305467
-
Install postgresql
sudo apt-get install postgresql libpq-dev phppgadmin pgadmin3 -
Log into postgresql as the postgres user
sudo su postgres -c psql -
In psql, using the username of the logged in user
postgres=# create user mma with password 'password';
CREATE ROLE
postgres=# alter user mma superuser;
ALTER ROLE
postgres=# create database omg_development;
CREATE DATABASE
postgres=# create database omg_test;
CREATE DATABASE
postgres=# grant all privileges on database omg_development to mma;
GRANT
postgres=# grant all privileges on database omg_test to mma;
GRANT
postgres=# \q
- Update
database.ymlwith
development:
<<: *default
host: localhost
database: omg_development
username: mma
password: password
- Add the Redis repository to the Ubuntu source repositories.
sudo add-apt-repository ppa:redislabs/redis
- Update your Ubuntu packages.
sudo apt update
- Install Redis using the package installation program.
sudo apt install redis-server
- Run Redis server locally
redis-server
- Install gems
bundle install
- Setup the database
bundle exec rails db:setup
bundle exec rails server
yarn dev
This allows webpack to recompile assets continually, rather than on page reload.
bundle exec foreman start
We are using the grape gem to manage the API framework. Within this API, there are multiple API classes in
/app/api/omg which each should correspond to a particular subpath. A new endpoint class
must be mounted in the base API class api.rb
To transform response entities, we use grape-entity to add a simple DSL on top
of ActiveRecord models. For any model we want to transform in an API response, we should add
the following in the class:
def entity
Entity.new(self)
end
class Entity < Grape::Entity
expose :id
expose :name
expose :player_id, as: :playerId
endEach exposed attribute is one on the model, and we should also use the as option to alias any
attribute names with underscores to camel case.
bundle exec rake db:dropbundle exec rake db:createbundle exec rake db:migratebundle exec rake db:seed
or the script
sh reset_db.sh
Create an alias with alias reset_db='sh reset_db.sh'
bundle exec rake db:dropto drop the existing DBheroku pg:pull DATABASE_URL omg_development --app omgmod-rails-prodbin/rails db:environment:set RAILS_ENV=development
Typically need to reset the DB if the seeds change and the entire DB needs to be reseeded.
heroku pg:reset --app <heroku app>- resets the pg DB (can also use the Heroku UI)heroku run rake db:migrate --app <heroku app>heroku run rake db:seed --app <heroku app>