Skip to content

Developer Setup & Notes

drewteter edited this page Apr 18, 2023 · 32 revisions

How to Set Up 1-Click Locally

1. Prerequisites

The following need to be installed.

  • git
  • postgres
  • postgis
  • rbenv (ruby package manager) or asdf (multi-language version manager)
  • ruby
  • geos (geospatial library that supports the rgeo gem)
  • imagemagick (for manipulating image file uploads)

Install all of your prequisites using homebrew

brew install git postgres postgis rbenv ruby-build geos imagemagick

Add rbenv/asdf to bash so that it loads every time you open a terminal

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

Install Ruby

# asdf
asdf plugin add ruby
asdf install ruby 2.6.9

# rbenv
rbenv install 2.6.9

ruby -v

2. Clone the Project

git clone https://github.com/camsys/oneclick-core.git

3. Setup Ruby Version

Setup rbenv or asdf to use ruby 2.6.9

cd oneclick-core

# asdf
asdf local ruby 2.6.9

# rbenv
rbenv local 2.6.9

Ruby <=2.4 is incompatible with OpenSSL 1.1, and it causes the ffi gem to fail to install. If you're not using ruby version 2.6.9, you may have to install OpenSSL 1.0 and then link it. For example:

brew install rbenv/tap/[email protected]
rvm install 2.1.2 -C --with-openssl-dir=`brew --prefix [email protected]`

If the above doesn't work then try the below:

sudo chown -R $(whoami) /Users/<YOUR USER NAME HERE>/.rbenv/versions/2.4.0/lib/ruby/gems/*
gem install ffi -v '1.9.23' -- --with-cflags="-Wno-error=implicit-function-declaration"
bundle install

4. Install Bundler and Gems

Install bundler and install gems.

gem install bundler
bundle install

If you receive a build error similar to this:

Installing pg 0.21.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

Install the gem manually in this manner: sudo gem install pg -v '0.21.0' Do not run the command sudo bundle install as it will cause unforeseen errors. If you run that command, you can undo it with sudo bundle install --system

If you have problems installing nokogiri, try the following

bundle config build.nokogiri --use-system-libraries
bundle install

5. Create Your Database

Make an alias for starting and stopping postgres:

alias start-psql='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
alias stop-psql='pg_ctl -D /usr/local/var/postgres stop -s -m fast'

You can now start and stop postgres by typing start-psql and stop-psql respectively.

(Optional: Set postgres to turn on at startup)

Note: Ensure postgres is running by typing pg_isready before moving on. You should see the message: "accepting connections"

This code creates your development database, loads the schema, and populates seed data:

rake db:setup

Optional: Add sample data to your development setup.

rake db:sample:all

Note: If you're using the Ecolane test user, One Click Core automatically inserts that user into the database when you try logging in with it. This user is built using Ecolane's booking API.

6. Translations

To build locales and load locale files, run:

rake simple_translation_engine:update

7. Setup local_env.yml file

Locally, you can configure ENV variables using a local_env.yml file. Copy the example file (local_env.yml.example), rename to local_env.yml, and uncomment, modify, or add any ENV variables needed to configure your app properly.

8. Start Your Server

rails s

Open a browser and go to localhost:3000.

Login with

email: [email protected]
pword: welcome1

Developer Notes

OCC Configuration

Once you have your app set up and you can successfully navigate to the Admin Console, you will need to do some configuration. Check out the Wiki page on Configuration for more information. At minimum you'll need to set at minimum the URL of the Open Trip Planner Server.

From there you can set up external booking APIs as needed depending on the particular One Click project you're working on.

In addition you'll need to set up Geographies, and a Transportation Service.

If you need help with configuration options, check or ask for the QA instance of One Click that you are working on. There you can grab whatever config options you need and plug them into your local instance.

See also the OCC New Server Setup Wiki page.

PostGIS database reset issue

You may run into the following error when running migrations, especially during rake db:reset:

PG::UndefinedObject: ERROR:  type "geometry" does not exist

To fix this, follow the steps outlined here (https://stackoverflow.com/questions/7001447/postgis-error-type-geography-does-not-exist):

  1. Open the psql console. On heroku, you can do this by running heroku pg:psql -a app-name
  2. Make sure you're connected to the right database, and run CREATE EXTENSION Postgis;
  3. Quit psql with \q.
  4. Re-run migrations; they should work now.

OneClick Module Engines

Modules are included by adding the module name as an environment variable, set to any truthy value (e.g. "true"). Locally, this can be achieved by creating a config/oneclick_modules.rb file. This can be copied over from config/oneclick_modules.rb.sample as a starting point. On Heroku, these variables can be set directly as heroku config variables.

To set up the OneclickReferNET engine:

Locally:

  1. Create a copy of config/oneclick_modules.rb.sample in the config directory and rename it oneclick_modules.rb.
  2. Add or un-comment the line: ENV["ONECLICK_REFERNET"] = "true"
  3. [THIS IS NO LONGER NECESSARY]run bundle install, rake oneclick_refernet:install:migrations and rake db:migrate
  4. run rake oneclick_refernet:load_database to import the ReferNET database. This will take a while.

Heroku:

  1. In the Settings tab for your app, click "Reveal Config Vars". Create a new variable with KEY = ONECLICK_REFERNET and VALUE = true.
  2. May need to do heroku restart -a app-name or something to get it to reinstall gems.
  3. [THIS IS NO LONGER NECESSARY] run rake oneclick_refernet:install:migrations
  4. run heroku run rake db:migrate -a app-name
  5. run rake oneclick_refernet:load_database to import the ReferNET database. This will take a while.
  6. If desired setting up a scheduled daily task to run rake oneclick_refernet:load_database_on_sunday will only run the load_database task if the day of the week is Sunday.

Oneclick IEUW(211 Ride) ReferNET Setup

Locally:

  1. follow steps 1 and 2 of the ReferNET local setup above
  2. run bundle exec rake ventura:load_database

OneClick uses a custom translation engine, which implements localization via a Locale table, a TranslationKey table, and a Translation table. It also allows automatic translations using the Google Translate API. See wiki for description of rake tasks.