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 '2.6.1'
- gem 'rails', '~> 5.2.6'
- gem 'image_processing', '~> 1.12'. More information: Image-processing
- gem 'bootstrap', '~> 4.3.1'. More information: Bootstrap
- gem 'jquery-rails'. More information: Jquery-rails
- gem "aws-sdk-s3", "~> 1.103". More information: AWS SDK para Ruby
- gem "figaro", "~> 1.2". More information: Figaro
- gem "cocoon", "~> 1.2". More information: Cocoon
- gem "activestorage-validator", "~> 0.1.5". More information: ActiveStorage Validator
- gem "rails-erd", "~> 1.6". More information: Rails-erd
The final Game domain model is summarised in the next flowchart:
The model and the relations are specified as it follows:
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
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/..."