Skip to content

Commit

Permalink
added view for rendering categories, quizzes and questions
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Jul 16, 2021
1 parent 341c5f4 commit 71798f1
Show file tree
Hide file tree
Showing 31 changed files with 246 additions and 53 deletions.
5 changes: 4 additions & 1 deletion Dockerfile.generic
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ ENV SECRET_KEY_BASE "$SECRET_KEY_BASE"
RUN mkdir -p /opt/webapps/app/tmp/pids
WORKDIR /opt/webapps/app
COPY . .
RUN gem install bundler && bundle update --bundler && bundle config set without 'development test' && bundle install
RUN gem install bundler && bundle update --bundler && bundle install
RUN yarn install --check-files
RUN bundle exec rails webpacker:install
RUN bundle exec rails assets:precompile
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
gem 'sass-rails', '~> 5.1.0'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
Expand Down
25 changes: 16 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ GEM
marcel (1.0.1)
method_source (1.0.0)
mini_mime (1.1.0)
mini_portile2 (2.5.3)
minitest (5.14.4)
msgpack (1.4.2)
nested_form (0.3.2)
nio4r (2.5.7)
nokogiri (1.11.7)
mini_portile2 (~> 2.5.0)
nokogiri (1.11.7-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
pg (1.2.3)
Expand Down Expand Up @@ -236,8 +234,17 @@ GEM
rspec-support (~> 3.10)
rspec-support (3.10.2)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.1.0)
railties (>= 5.2.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
Expand All @@ -256,7 +263,7 @@ GEM
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
spring (2.1.1)
sprockets (4.0.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.2)
Expand Down Expand Up @@ -295,7 +302,7 @@ GEM
zeitwerk (2.4.2)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
bootsnap (>= 1.4.4)
Expand All @@ -315,7 +322,7 @@ DEPENDENCIES
rails_admin (~> 2.0)
rexml (~> 3.2, >= 3.2.4)
rspec-rails (~> 5.0.0)
sass-rails (>= 6)
sass-rails (~> 5.1.0)
selenium-webdriver
simplecov (= 0.17.1)
spring
Expand All @@ -329,4 +336,4 @@ RUBY VERSION
ruby 3.0.2p107

BUNDLED WITH
2.2.23
2.2.24
3 changes: 3 additions & 0 deletions app/assets/stylesheets/categories.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Categories controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/quiz.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Quiz controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
8 changes: 8 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CategoriesController < ApplicationController
def show
@questions = Question.where(category_id: params[:id])

category = Category.find(params[:id])
@multiply = category.multiply
end
end
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class HomeController < ApplicationController
skip_before_action :authenticate_user!, :only => [:index]

def index
@quizzes = Quiz.all
end
end
7 changes: 7 additions & 0 deletions app/controllers/quiz_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class QuizController < ApplicationController

def show
@quiz = Quiz.find(params[:id])
@categories = Category.where(quiz_id: @quiz.id)
end
end
2 changes: 2 additions & 0 deletions app/helpers/categories_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CategoriesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/quiz_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module QuizHelper
end
24 changes: 24 additions & 0 deletions app/views/categories/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1>Questions</h1>

<% if @questions.any? %>

<%= form_with do |f| %>

<ul>
<% @questions.each do |question| %>
<li><%= question.title %></li>
<hr>
<ul>
<% if @multiply %>
<%= f.collection_check_boxes :answer_id, Answer.where(question_id: question.id), :id, :title_en %>
<% else %>
<%= f.collection_radio_buttons :answer_id, Answer.where(question_id: question.id), :id, :title_en %>
<% end %>
</ul>
<% end %>
</ul>

<% end %>
<% else %>
<p>No any questions</p>
<% end %>
18 changes: 16 additions & 2 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<h1>Home</h1>

<h2>Quizzes:</h2>
<% if @quizzes.any? %>
<ul>
<% @quizzes.each do |quiz| %>
<li>
<%= link_to quiz_path(quiz) do %>
<%= quiz.title %>
<% end %>
</li>
<% end %>
</ul>
<% else %>
<p>No any quizzes</p>
<% end %>
17 changes: 17 additions & 0 deletions app/views/quiz/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>
Choose your category
</h1>

<% if @categories.any? %>
<ul>
<% @categories.each do |category| %>
<li>
<%= link_to category_path(category) do %>
<%= category.title %>
<% end %>
</li>
<% end %>
</ul>
<% else %>
<p>No Any Categories</p>
<% end %>
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nmmjPIYi31KQUAt4zkUVSZ+QrImBJF6b4nRsg7/J8DHuMWT0otIk4eOrZs6E2HvFSbxqx3kyjkDIjzPLPYI9/YX9z9Z5ZDGxMlPBmAbsXXtyAFp2g8e5Bjw64VzQhQmqQWkn20LWw13rcKFabn1hRgB0bx3/U12dqzD0SAslQSYpsxZWgH195Ivtt2f49VIAd0f9C86Fk/FmyUE/N3aXMtAcC9GZDZdfw3SOX/pSE+B0Zo97Cg+uKuwTne72FRQlMGRK/PiGkrtXeuedTiao7e1lwPIrqOrkvVXBuJ+4oiTzgNwWwILj/YAEWIi1BbtLYClkXiCIJy5q4xX1FfBqMl835Qi4V6AaYun7okObrVF9mji4BM1AkTQNmtjzSMP2fqu1n7gAgFPV0la6eVEVxFWNUBhXN0X8bA+P--b7GlQ5hc2O48fwW/--fyvygLf/+b1saj1gUuWRqw==
jI2cuUFqWtfsPyA8z2Xh88MEaEOcLYeK6G9G8BAvWjdFB6vTBLo8OmVsH7fbGl+ZInR4EeUDrXUO2Xq4uZw0vcxw95TDnIvaxdWHdMIXbvXSPOSlFY8o9/tQujlU6kefhb0mJa0jXPlepgzqJ6xc8AzeVURr1geBMGvG7lazNEkDRwLgfxHAtNw3jUpe4SatYghlXsw6CQ772HvxlJtICpGT5saisELmttWXPZee2zahy2eWUQBSqYtYiqduVwY5vy8ngDRqS6dLYcYdaMikWH4rGI63ADYRkfs94guext6SjY1mriVrzCnqCI0AyMesPpHe6e6GBah1tmaz/iRSXXJ8B+aSi5iuR88WtcHiJSyPaAQryrQrKb4yZoKpTSBqNaVlUOGMrBnyCRRJ60QNapG4FDGkL9QX5CNT--hJE7dOrJqQIG4+Fm--qJLYUILiJwMR5xzEO1ofBQ==
3 changes: 2 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.webpacker.check_yarn_integrity = false

# Code is not reloaded between requests.
config.cache_classes = true
Expand Down Expand Up @@ -50,7 +51,7 @@

# Include generic and useful information about system operation, but avoid logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII).
config.log_level = :info
config.log_level = :debug

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
Expand Down
16 changes: 15 additions & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
require_relative 'production'
require_relative 'production'

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

require 'syslog/logger'
config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new(ENV['app_name'] || 'accreditation'))

# Enable stdout logger
config.logger = Logger.new(STDOUT)

# Set log level
config.log_level = :ERROR

end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Rails.application.routes.draw do
resources :quiz, only: [ :show ]
resources :categories, only: [ :show ]

devise_for :users
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
root 'home#index'
Expand Down
25 changes: 0 additions & 25 deletions config/secrets.yml

This file was deleted.

5 changes: 5 additions & 0 deletions config/webpack/staging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'staging'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
22 changes: 13 additions & 9 deletions config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ default: &default
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
webpack_compile_output: true

# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: true

webpack_compile_output: false

# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []

additional_paths: []

# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false

# Extract and emit a css file
extract_css: false
extract_css: true

static_assets_extensions:
- .jpg
Expand All @@ -37,6 +43,7 @@ default: &default
- .js
- .sass
- .scss
- .less
- .css
- .module.sass
- .module.scss
Expand All @@ -50,7 +57,6 @@ default: &default
development:
<<: *default
compile: true

# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
Expand All @@ -65,7 +71,6 @@ development:
disable_host_check: true
use_local_ip: false
quiet: false
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
Expand All @@ -74,7 +79,8 @@ development:

test:
<<: *default
compile: true
compile: false
cache_manifest: true

# Compile test packs to a separate directory
public_output_path: packs-test
Expand All @@ -85,17 +91,15 @@ production:
# Production depends on precompilation of packs prior to booting for performance.
compile: false

# Extract and emit a css file
extract_css: true

# Cache manifest.json for performance
cache_manifest: true

staging:
<<: *default

# Production depends on precompilation of packs prior to booting for performance.
compile: true
compile: false

# Cache manifest.json for performance
cache_manifest: true

5 changes: 5 additions & 0 deletions db/migrate/20210716071248_add_new_field_to_categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNewFieldToCategories < ActiveRecord::Migration[6.1]
def change
add_column :categories, :multiply, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 71798f1

Please sign in to comment.