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

Commit f6419a3

Browse files
author
Yuma Soga
committed
#35 Add notice for form sent
1 parent 1cac9a2 commit f6419a3

File tree

8 files changed

+27
-2
lines changed

8 files changed

+27
-2
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ gem 'redcarpet'
4747

4848
gem 'slack-notifier'
4949

50+
gem 'toastr-rails'
51+
5052
group :development, :test do
5153
gem 'sqlite3'
5254
gem 'byebug'

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ GEM
281281
thread_safe (0.3.6)
282282
tilt (2.0.8)
283283
timecop (0.9.1)
284+
toastr-rails (1.0.3)
285+
railties (>= 3.1.0)
284286
travis (1.8.8)
285287
backports
286288
faraday (~> 0.9)
@@ -344,6 +346,7 @@ DEPENDENCIES
344346
spring
345347
sqlite3
346348
timecop
349+
toastr-rails
347350
travis
348351
turbolinks
349352
uglifier (>= 1.3.0)

app/assets/javascripts/application.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//= require rails-ujs
1414
//= require turbolinks
1515
//= require jquery3
16+
//= require toastr
1617
//= require popper
1718
//= require bootstrap-sprockets
1819
//= require_tree .
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$(document).on 'turbolinks:load', ->
2+
if $.trim($('#info > .notice').html())!=''
3+
toastr.success $('#info > .notice').text()
4+
console.log 'Show Notice:' + $('#info > .notice').text()
5+
else if $.trim($('#info > .alert').html())!=''
6+
toastr.error $('#info > .alert').text()
7+
console.log 'Show Alert:' + $('#info > .alert').text()
8+
else
9+
console.log 'No Words'

app/assets/stylesheets/application.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
@import "font-awesome";
1717

18+
@import "toastr";
19+
1820
@import "bootstrap-creative/creative";
1921
@import "pages";
2022
@import "posts";

app/controllers/staticpages_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ def contact_form_send
1515

1616
respond_to do |format|
1717
if @contact_form.save
18-
format.html { redirect_to :action => "index", notice: 'Post was successfully updated.' }
18+
flash[:notice] = 'お問い合わせの送信が完了しました'
19+
format.html { redirect_to :action => "index" }
1920
format.json { render :show, status: :ok, location: @contact_form }
2021
else
21-
format.html { render :contact_form }
22+
flash.now[:alert] = '入力に不備があるか、何かの不具合で送れませんでした。もう一度お試しください。'
23+
format.html { render :contact }
2224
format.json { render json: @contact_form.errors, status: :unprocessable_entity }
2325
end
2426
end

app/views/layouts/pages.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
%link{:href => "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800", :rel => "stylesheet", :type => "text/css"}/
2727
%link{:href => "https://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic", :rel => "stylesheet", :type => "text/css"}/
2828
%body#page-top
29+
#notice{style: "display:none" }
30+
= notice
31+
2932
/ Navigation
3033
%nav#mainNav.navbar.navbar-expand-lg.navbar-light.fixed-top
3134
.container-fluid

app/views/layouts/staticpages.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
%link{:href => "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800", :rel => "stylesheet", :type => "text/css"}/
2525
%link{:href => "https://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic", :rel => "stylesheet", :type => "text/css"}/
2626
%body#page-top
27+
- flash.each do |key, value|
28+
#info{style: "display:none" }
29+
= content_tag(:p, value, class: "#{key}")
2730
/ Navigation
2831
%nav#mainNav.navbar.navbar-expand-lg.navbar-light.fixed-top
2932
.container-fluid

0 commit comments

Comments
 (0)