Skip to content
This repository was archived by the owner on Mar 19, 2020. It is now read-only.

Commit 1cac9a2

Browse files
author
Yuma Soga
committed
#35 Update contact forms
1 parent d9a04e6 commit 1cac9a2

File tree

11 files changed

+118
-19
lines changed

11 files changed

+118
-19
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ gem 'simple_form'
4545

4646
gem 'redcarpet'
4747

48+
gem 'slack-notifier'
49+
4850
group :development, :test do
4951
gem 'sqlite3'
5052
gem 'byebug'

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ GEM
265265
json (>= 1.8, < 3)
266266
simplecov-html (~> 0.10.0)
267267
simplecov-html (0.10.2)
268+
slack-notifier (2.3.2)
268269
spring (2.0.2)
269270
activesupport (>= 4.2)
270271
sprockets (3.7.2)
@@ -339,6 +340,7 @@ DEPENDENCIES
339340
sdoc (~> 0.4.0)
340341
simple_form
341342
simplecov
343+
slack-notifier
342344
spring
343345
sqlite3
344346
timecop
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
class StaticpagesController < ApplicationController
22
def index
3+
@contact_form = ContactForm.new
34
end
45
def next_event_is_still_planned
56
end
67
def ninjas_works
78
end
9+
def contact
10+
@contact_form = ContactForm.new
11+
end
12+
def contact_form_send
13+
14+
@contact_form = ContactForm.new(contact_form_params)
15+
16+
respond_to do |format|
17+
if @contact_form.save
18+
format.html { redirect_to :action => "index", notice: 'Post was successfully updated.' }
19+
format.json { render :show, status: :ok, location: @contact_form }
20+
else
21+
format.html { render :contact_form }
22+
format.json { render json: @contact_form.errors, status: :unprocessable_entity }
23+
end
24+
end
25+
26+
end
27+
28+
private
29+
def contact_form_params
30+
params.require(:contact_form).permit(:name, :email, :subject, :body)
31+
end
832
end

app/models/contact_form.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class ContactForm
2+
include ActiveModel::Model
3+
include ActiveModel::Attributes
4+
#include ActiveModel::Callbacks
5+
6+
attr_accessor :name, :email, :subject, :body
7+
define_model_callbacks :save
8+
9+
validates :name, presence: true
10+
validates :email, presence: true
11+
validates :subject, presence: true
12+
validates :body, presence: true
13+
14+
def save
15+
run_callbacks :save do
16+
return false if invalid?
17+
@name = self.name
18+
@email = self.email
19+
@subject = self.subject
20+
@body = self.body
21+
22+
bodyAttachments = {"title":"メンターお問いあわせ",
23+
"text": "\n\n\n*Email* :\n" + @email +
24+
"\n\n*お名前* :\n" + @name +
25+
"\n\n*件名* :\n" + @subject +
26+
"\n\n*本文* :\n" + @body
27+
};
28+
29+
massage_body = "<!channel> お問い合わせフォームより新しい通知が来ています! \n"
30+
31+
hooks_url = ENV['SLACK_INCOMING_WEBHOOKS_URL']
32+
notifier = Slack::Notifier.new hooks_url, channel: "#各種お問い合わせボード"
33+
notifier.post attachments: [bodyAttachments], text: massage_body
34+
true
35+
end
36+
end
37+
end

app/views/staticpages/_form.html.haml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
= simple_form_for @contact_form, :html => { :class => 'form-horizontal' }, :url => { :action => 'contact_form_send'} do |f|
2+
= f.input :name, as: :string, placeholder: 'お名前'
3+
= f.input :email, as: :string, placeholder: 'メールアドレス'
4+
= f.input :subject, as: :string, placeholder: '件名'
5+
= f.input :body, as: :text, placeholder: '本文を入力してください。', :input_html => { :rows => 5 }
6+
= f.submit '送信', :class => 'btn btn-primary'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%section#contact
2+
.container
3+
.row
4+
.col-lg-8.mx-auto.text-center
5+
%h2.section-heading
6+
%i.fa.fa-envelope-o.sr-contact.mx-3
7+
Contact us
8+
%hr.my-4/
9+
%p.mb-5 何か気になることがございましたら、お気軽にお問い合わせください!
10+
.row
11+
.col-lg-8.mx-auto.mw-100
12+
= render 'form'

app/views/staticpages/index.html.haml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,7 @@
239239
%p.mb-5 何か気になることがございましたら、お気軽にお問い合わせください!
240240
.row
241241
.col-lg-8.mx-auto.mw-100
242-
= simple_form_for :contact_form, :html => { :class => 'form-horizontal' } do |f|
243-
= f.input :name, as: :string, placeholder: 'お名前'
244-
= f.input :email, as: :string, placeholder: 'メールアドレス'
245-
= f.input :subject, as: :string, placeholder: '件名'
246-
= f.input :body, as: :text, placeholder: '本文を入力してください。', :input_html => { :rows => 5 }
247-
= f.submit '送信', :class => 'btn btn-primary'
242+
= render 'form'
248243
.row
249244
.col-lg-4.mx-auto.my-3.p-2.mw-100
250245
.fb-page.fb-page-style{"data-adapt-container-width" => "true", "data-hide-cover" => "false", "data-href" => "https://www.facebook.com/Coderdojo.Konan/", "data-show-facepile" => "true", "data-small-header" => "false", "data-tabs" => "timeline"}

config/routes.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
resources :posts
33
# The priority is based upon order of creation: first created -> highest priority.
44
# See how all your routes lay out with "rake routes".
5-
5+
66
root 'staticpages#index'
7-
7+
8+
post '/send-contact-form' => 'staticpages#contact_form_send'
9+
10+
get '/contact-form' => 'staticpages#contact'
11+
812
get '/pages' => 'pages#index'
913
get '/next-event-is-still-planned' => 'staticpages#next_event_is_still_planned'
1014
get '/ninjas-works' => 'staticpages#ninjas_works'
11-
15+
1216
resources :pages, only: [:show], :path => '/'
13-
17+
1418
# Example of regular route:
1519
# get 'products/:id' => 'catalog#view'
1620

db/pages/disaster-response.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,49 @@
99
他のCoderDojo とは異なる場合もありますのでご注意ください。
1010

1111
# 警報発令時・災害時の対応
12+
---
13+
<br>
1214

1315
## 開催前
16+
---
1417

15-
以下の場合、CoderDojo 岡山 岡南 の開催は中止です
18+
以下の場合、CoderDojo 岡山 岡南 の開催は中止・延期となります
1619

1720
- 岡山地域で、受付開始2時間前までに暴風・暴風雨・大雪・暴風雪・津波・土砂・噴火警報発令のいずれかが発令の場合。
1821
- 岡山地域で、開始4時間前〜開催中に避難準備情報、避難勧告、避難指示のいずれかが発令された場合。
1922
- その他に、非常に高い確率で、上記各種警報・各種情報が発令されると予測される場合。
2023
- 会場への来場が非常に危険で、難しいと運営によって判断された場合。
21-
※ 以上に当てはまらず、開催される場合でも、来場が難しい・危険と判断される場合は、開催の有無にかかわらず、無理をせず自己判断で自主キャンセルをしてください。
2224

23-
また、当日前に災害救助法が適用される災害が岡山地域に出るような災害が発生した時点で、その後のイベント全てを事前連絡無しでキャンセルする可能性がございます。
25+
※ 以上に当てはまらず、開催される場合でも、来場が難しい・危険と判断される場合は、開催の有無にかかわらず、
26+
無理をせず自己判断で自主キャンセルをしてください。
27+
28+
また、当日前に災害救助法が適用される災害が岡山地域に出るような災害が発生した時点で、
29+
その後のイベント全てを事前連絡無しでキャンセルする可能性がございます。
2430

2531
※ Yahoo!防災情報アプリ などを活用し、情報を収集しながら来場ください。
2632

2733
## 開催中
28-
34+
---
2935
基本的に下記の場合、開催は即中止します。
30-
また、一人での帰宅が困難だと判断される場合、保護者様によるお迎えをお頼みすることがあります
36+
また、一人での帰宅が困難だと判断される場合、保護者様によるお迎えをお願いすることがあります
3137

32-
- 岡山市で、開催中に、暴風・暴風雨・大雪・暴風雪・津波・土砂・噴火警報発令のいずれかが発令され、会場にいることが非常に危険だと判断されたとき。
38+
- 岡山市で、開催中に、暴風・暴風雨・大雪・暴風雪・津波・土砂・噴火警報発令のいずれかが発令され、
39+
会場にいることが非常に危険だと判断されたとき。
3340
- 岡山市で、開催中に、避難準備情報、避難勧告、避難指示のいずれかが発令された場合。
3441
- その他に、非常に高い確率で、上記各種警報・各種情報が発令されると予測される場合。
3542
- その他に、重大な災害が起こる可能性があり、帰宅させたほうがいいと運営によって判断されたとき。
3643

3744

3845
# 中止の場合の連絡手段について
39-
46+
---
4047
## 開催前
41-
48+
---
4249
開催申込時に入力していただいたメールアドレスにお知らせいたします。
4350

4451
また、各種SNSでもお知らせします。
4552

4653
## 開催中
47-
54+
---
4855
メールアドレスにご連絡します。
4956

5057
また、余りにも緊急性の高い場合、緊急連絡先にもご連絡します。

spec/factories/contact_forms.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FactoryBot.define do
2+
factory :contact_form do
3+
4+
end
5+
end

spec/models/contact_form_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe ContactForm, type: :model do
4+
pending "add some examples to (or delete) #{__FILE__}"
5+
end

0 commit comments

Comments
 (0)