|
| 1 | +--- |
| 2 | +title: Running Server with Rails |
| 3 | +layout: default |
| 4 | +parent: Guides |
| 5 | +--- |
| 6 | + |
| 7 | +{: .help} |
| 8 | +> After Monolith Improvements, we should consider whether to deprecate this guide. If we keep it, this page needs some formatting cleanup. |
| 9 | +
|
| 10 | +### Run directly with Ruby (lightweight, but it involves manual installation which happens at your own risk and we won't be able to assist with detailed troubleshooting) |
| 11 | + |
| 12 | +- Ensure you have the correct [Ruby version](./.ruby-version) installed. We recommend using a Ruby version manager like [rvm](https://rvm.io/rvm/install) or [rbenv](https://github.com/rbenv/rbenv). They should both read the `.ruby-version` file to use the correct version (`rvm current` or `rbenv version` to confirm). |
| 13 | +- Ensure [Bundler 2](https://bundler.io/v2.0/guides/bundler_2_upgrade.html) is installed |
| 14 | + - To update from bundler 1: |
| 15 | + ``` |
| 16 | + gem update --system |
| 17 | + bundle update --bundler |
| 18 | + ``` |
| 19 | + - Or, if you haven't installed bundler previously: |
| 20 | + ``` |
| 21 | + gem update --system |
| 22 | + gem install bundler |
| 23 | + ``` |
| 24 | +- Set up git pre-commit hook. Optional, but very useful. |
| 25 | + ```shell |
| 26 | + (cd WcaOnRails; bundle install && bin/yarn && bundle exec overcommit --install) |
| 27 | + ``` |
| 28 | + If some changes are made to this hook, you will have to update it running this command from the repository's root directory: `BUNDLE_GEMFILE=WcaOnRails/Gemfile bundle exec overcommit --sign`. |
| 29 | +- Install [MySQL 8.0](https://dev.mysql.com/doc/refman/8.0/en/linux-installation.html), and set it up with a user with username "root" with an empty password. |
| 30 | + If it poses problems, try the following: |
| 31 | + ```shell |
| 32 | + # Run MySQL CLI as administrator and set an empty password for the root user: |
| 33 | + sudo mysql -u root |
| 34 | + ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''; |
| 35 | + ``` |
| 36 | +- Install dependencies and load development database. |
| 37 | + 1. `cd WcaOnRails/` |
| 38 | + 2. [Install Node.js](https://nodejs.org/en/) and [yarn](https://yarnpkg.com/en/docs/install), we need them for our javascript assets. |
| 39 | + Feel free to take a look at our [chef recipe](https://github.com/thewca/worldcubeassociation.org/blob/master/chef/site-cookbooks/wca/recipes/default.rb#L6-L23) |
| 40 | + for the accurate versions we use and how we install them. |
| 41 | + Please note that other versions may work, but it is not guaranteed. |
| 42 | + 3. Install `libyaml` using your package manager of choice, eg. [Mac](https://formulae.brew.sh/formula/libyaml) or [Ubuntu](https://launchpad.net/ubuntu/+source/libyaml) |
| 43 | + 4. `bundle install && bin/yarn` |
| 44 | + 5. `bin/rake db:load:development` - Download and import the [developer's database export](https://github.com/thewca/worldcubeassociation.org/wiki/Developer-database-export). Depending on your computer it may take a long time. Alternatively you can run `bin/rake db:reset` which will create the database and seed it with random data (it's way faster, but less representative of our website content). |
| 45 | + 6. `bin/rails server` - Run rails. The server will be accessible at localhost:3000 |
| 46 | +- Run tests. |
| 47 | + 1. `RAILS_ENV=test bin/rake db:reset` - Set up test database. |
| 48 | + 2. `RAILS_ENV=test bin/rake assets:precompile` - Compile some assets needed for tests to run. |
| 49 | + 3. `bin/rspec` - Run tests. |
| 50 | +- [Mailcatcher](http://mailcatcher.me/) is a good tool for catching emails in development. |
0 commit comments