Skip to content

denisse-orellana/game_download

Repository files navigation

Board Games

This project involves the development of a storage database system about board games which includes images and documents. The storage implementation is made through the Active Storage and the Amazon Simple Storage Service (Amazon S3).

Ruby & Rails version

  • ruby '2.6.1'
  • gem 'rails', '~> 5.2.6'

Ruby & Rails gems

Diagram model

The final Game domain model is summarised in the next flowchart:

game_domain_model

Defining the model structures

The model and the relations are specified as it follows:

game_diagram

As it can be seen above, the rule, component and boxes models are part of the game model, and each one of them will have files attached. These are generated as:

rails g scaffold Rule name content game:references
rails g scaffold Component name typecomp:integer game:references
rails g scaffold Box content game:references
rails g scaffold Game title description

The associations are added as:

class Rule < ApplicationRecord
    belongs_to :game
    has_one_attached :document
end

class Component < ApplicationRecord
    belongs_to :game
    has_many_attached :images
end

class Box < ApplicationRecord
    belongs_to :game
    has_one_attached :image
end

class Game < ApplicationRecord
  has_one :rule, dependent: :destroy
  has_many :components, dependent: :destroy
  has_one :box, dependent: :destroy
end

The functionality of the relations can be checked in the rails console:

Game.new.rule
Game.new.components
Game.new.box
Rule.new.game
Component.new.game
Box.new.game

Amazon Simple Storage Service (Amazon S3)

First, the gem for AWS SDK is added:

bundle add aws-sdk-s3

The creation of a Bucket and a User is needed to the implementation of the service. Next, the gem to secure the configuration on Rails applications is added and installed:

bundle add figaro
bundle exec figaro install

After the configuration of the keys, the location of the files can be checked by searching for the service url on the rails console just as:

Game.last.box.image.service_url
"https://g46game.s3.amazonaws.com/..."

Game.last.rule.document.service_url
https://g46game.s3.amazonaws.com/..."

Game.last.components.last.images.last.service_url
"https://g46game.s3.amazonaws.com/..."