Skip to content

A Ruby on Rails with MySQL template, for quick development setup in Crafting Sandbox.

License

Notifications You must be signed in to change notification settings

crafting-dev/template-ruby-rails

Repository files navigation

Ruby on Rails with MySQL template for Crafting Sandbox

This is a Ruby on Rails with MySQL template, configured for quick development setup in Crafting Sandbox.

Specifications

This template was created with MySQL and without Minitest:

rails new template-ruby-rails -d mysql -T

Rspec is used for testing instead:

gem 'rspec-rails', '~> 5.0.0'

Rubocop is used for linting, enforcing many of the guidelines outlined in the community Ruby Style Guide.

gem 'rubocop-rails', require: false

The shell script sandbox.sh is used to configure sandbox for quick workspace setup. The manifest file .sandbox/manifest.yaml uses it during build stage when creating a new sandbox using this template.

config/database.yml is modified to use the preconfigured credentials set in App configuration. The environment variables MYSQL_SERVICE_HOST and MYSQL_SERVICE_PORT come already populated in sandbox.

Pings Controller

This template comes with a Pings controller already generated:

rails g controller Pings pong

whereby the action pong is defined as:

def pong
  @pong = {
    ping: @ping.presence || "To ping, or not to ping...",
    received_at: @current_time
  }

  render json: @pong
end

with the route:

get 'ping', to: 'pings#pong'

This action receives a parameter string, and responds with the param string and the current time. For example:

$ curl --request GET 'localhost:3000/ping?ping=hello'
{"ping":"hello","received_at":"XXXX-XX-XXXXX:XX:XX.XXXX"}

App Definition

The following App Definition was used to create this template:

endpoints:
- name: api
  http:
    routes:
    - pathPrefix: "/"
      backend:
        target: ruby-rails
        port: api
    authProxy:
      disabled: true
workspaces:
- name: ruby-rails
  description: Template backend using Ruby/Rails
  ports:
  - name: api
    port: 3000
    protocol: HTTP/TCP
  checkouts:
  - path: backend
    repo:
      git: https://github.com/crafting-dev/template-ruby-rails
  packages:
  - name: ruby
    version: 2.7.2
  - name: nodejs
    version: 16.12.0
dependencies:
- name: mysql
  serviceType: mysql
  version: '8'
  properties:
    database: superhero
    password: batman
    username: brucewayne

About

A Ruby on Rails with MySQL template, for quick development setup in Crafting Sandbox.

Resources

License

Stars

Watchers

Forks