Skip to content

Commit

Permalink
Merge pull request #1 from telva0527/develop
Browse files Browse the repository at this point in the history
質問回答アプリの提出
  • Loading branch information
taik0527 committed Jul 2, 2021
2 parents a306bd6 + 609dde5 commit 45c4dfc
Show file tree
Hide file tree
Showing 86 changed files with 1,000 additions and 70 deletions.
9 changes: 8 additions & 1 deletion Gemfile
Expand Up @@ -25,7 +25,7 @@ gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
Expand Down Expand Up @@ -60,3 +60,10 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'bootstrap'
gem 'slim-rails'
gem 'html2slim'
gem 'ransack'
gem 'kaminari'
gem 'mailcatcher'
85 changes: 85 additions & 0 deletions Gemfile.lock
Expand Up @@ -47,9 +47,16 @@ GEM
archive-zip (0.12.0)
io-like (~> 0.3.0)
arel (9.0.0)
autoprefixer-rails (10.2.5.1)
execjs (> 0)
bcrypt (3.1.16)
bindex (0.8.1)
bootsnap (1.7.5)
msgpack (~> 1.0)
bootstrap (5.0.1)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 2.9.2, < 3)
sassc-rails (>= 2.0.0)
builder (3.2.4)
byebug (11.1.3)
capybara (3.35.3)
Expand All @@ -73,16 +80,37 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.1.8)
crass (1.0.6)
daemons (1.4.0)
erubi (1.10.0)
eventmachine (1.2.7)
execjs (2.8.1)
ffi (1.15.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
haml (5.2.1)
temple (>= 0.8.0)
tilt
hpricot (0.8.6)
html2slim (0.2.0)
hpricot
i18n (1.8.10)
concurrent-ruby (~> 1.0)
io-like (0.3.1)
jbuilder (2.11.2)
activesupport (>= 5.0.0)
json (2.5.1)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
kaminari-activerecord (= 1.2.1)
kaminari-core (= 1.2.1)
kaminari-actionview (1.2.1)
actionview
kaminari-core (= 1.2.1)
kaminari-activerecord (1.2.1)
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -92,18 +120,33 @@ GEM
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
mailcatcher (0.2.4)
eventmachine
haml
i18n
json
mail
sinatra
skinny (>= 0.1.2)
sqlite3-ruby
thin
marcel (1.0.1)
method_source (1.0.0)
mini_mime (1.1.0)
minitest (5.14.4)
msgpack (1.4.2)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.7)
nokogiri (1.11.6-x86_64-darwin)
racc (~> 1.4)
popper_js (2.9.2)
public_suffix (4.0.6)
puma (3.12.6)
racc (1.5.2)
rack (2.2.3)
rack-protection (2.1.0)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.6)
Expand Down Expand Up @@ -131,10 +174,15 @@ GEM
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (13.0.3)
ransack (2.4.1)
activerecord (>= 5.2.4)
activesupport (>= 5.2.4)
i18n
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.1.1)
ruby2_keywords (0.0.4)
ruby_dep (1.5.0)
rubyzip (2.3.0)
sass (3.7.4)
Expand All @@ -148,9 +196,32 @@ GEM
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)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
skinny (0.2.2)
eventmachine (~> 1.0)
thin
slim (4.1.0)
temple (>= 0.7.6, < 0.9)
tilt (>= 2.0.6, < 2.1)
slim-rails (3.2.0)
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 5.0)
spring (2.1.1)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand All @@ -163,6 +234,13 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
temple (0.8.2)
thin (1.8.1)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (1.1.0)
thread_safe (0.3.6)
tilt (2.0.10)
Expand All @@ -188,17 +266,24 @@ PLATFORMS
x86_64-darwin-20

DEPENDENCIES
bcrypt (~> 3.1.7)
bootsnap (>= 1.1.0)
bootstrap
byebug
capybara (>= 2.15)
chromedriver-helper
coffee-rails (~> 4.2)
html2slim
jbuilder (~> 2.5)
kaminari
listen (>= 3.0.5, < 3.2)
mailcatcher
puma (~> 3.11)
rails (~> 5.2.1)
ransack
sass-rails (~> 5.0)
selenium-webdriver
slim-rails
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
Expand Down
25 changes: 1 addition & 24 deletions README.md
@@ -1,24 +1 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
# 質問回答アプリ
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/questions.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/sessions.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/users.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/answers.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/questions.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/sessions.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/questions.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the Admin::Questions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/sessions.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the Admin::Sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/users.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the Admin::Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/answers.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the answers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
15 changes: 0 additions & 15 deletions app/assets/stylesheets/application.css

This file was deleted.

1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
@@ -0,0 +1 @@
@import "bootstrap";
3 changes: 3 additions & 0 deletions app/assets/stylesheets/questions.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the questions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sessions.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
14 changes: 14 additions & 0 deletions app/controllers/admin/questions_controller.rb
@@ -0,0 +1,14 @@
class Admin::QuestionsController < ApplicationController
before_action :admin_required

def index
@q = Question.ransack(params[:q])
@questions = @q.result(distinct: true).page(params[:page])
end

def destroy
@question = Question.find(params[:id])
@question.destroy
redirect_to admin_questions_url, notice: "質問「#{@question.title}」を削除しました。"
end
end
21 changes: 21 additions & 0 deletions app/controllers/admin/sessions_controller.rb
@@ -0,0 +1,21 @@
class Admin::SessionsController < ApplicationController
skip_before_action :login_required

def new
end

def create
user = User.find_by(email: session_params[:email])
if user&.authenticate(session_params[:password]) && user.admin
session[:user_id] = user.id
session[:user_admin] = user.id
redirect_to admin_questions_path, notice: "ログインしました"
else
render :new
end
end

def session_params
params.require(:session).permit(:email, :password)
end
end
14 changes: 14 additions & 0 deletions app/controllers/admin/users_controller.rb
@@ -0,0 +1,14 @@
class Admin::UsersController < ApplicationController
before_action :admin_required

def index
@q = User.ransack(params[:q])
@users = @q.result(distinct: true).page(params[:page])
end

def destroy
@user = User.find(params[:id])
@user.destroy
redirect_to admin_users_url, notice: "ユーザー「#{@user.name}」を削除しました。"
end
end
28 changes: 28 additions & 0 deletions app/controllers/answers_controller.rb
@@ -0,0 +1,28 @@
class AnswersController < ApplicationController
def create
@answer = current_user.answers.new(answer_params.merge(question_id: params[:question_id]))
if @answer.save
unless current_user.mine?(@answer.question)
QuestionMailer.with(user: @answer.question.user, question: @answer.question).answer_created.deliver_later
end

User.related_to_question(@answer.question).distinct.each do |user|
next if user.id == current_user.id || user.mine?(@answer.question)

AnswerMailer.with(user: user, question: @answer.question).answer_created.deliver_later
end
redirect_to question_url(params[:question_id]), notice: "回答しました"
else
@question = @answer.question
@answers = Answer.where(question_id: @question.id).order(created_at: "DESC")
flash.now[:danger] = "回答の作成に失敗しました"
render 'questions/show'
end
end

private

def answer_params
params.require(:answer).permit(:body)
end
end
16 changes: 16 additions & 0 deletions app/controllers/application_controller.rb
@@ -1,2 +1,18 @@
class ApplicationController < ActionController::Base
helper_method :current_user
before_action :login_required

private

def current_user
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
end

def login_required
redirect_to login_url unless current_user
end

def admin_required
redirect_to root_url unless session[:user_admin]
end
end

0 comments on commit 45c4dfc

Please sign in to comment.