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

Commit 8848e31

Browse files
committed
close #15 back/cancel ボタンは直近の show/index へのリンク (含 query_string) となるようにした
1 parent dc9e1b4 commit 8848e31

File tree

7 files changed

+15
-5
lines changed

7 files changed

+15
-5
lines changed

app/controllers/application_controller.rb

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ApplicationController < ActionController::Base
77
respond_to :html
88

99
before_action :log_user_info
10+
before_action :set_location_to_back
1011

1112
# returns current +User+ if logged in
1213
# * *Returns* :
@@ -21,4 +22,9 @@ def current_user
2122
def log_user_info
2223
logger.info " user_id: #{session[:user_id]}, request_ip: #{request.ip}, session_id: #{session.id}" if session[:user_id]
2324
end
25+
26+
def set_location_to_back
27+
session[:location_to_back] = session[:last_location]
28+
session[:last_location] = request.fullpath if %w(index show).include?(action_name)
29+
end
2430
end

app/helpers/application_helper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ module ApplicationHelper
33
def shallow_args(parent, child)
44
child.try(:new_record?) ? [parent, child] : child
55
end
6+
7+
def link_to_back(*args)
8+
link_to args.shift, session[:location_to_back] || root_path, *args
9+
end
610
end

app/views/comments/_form.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
.form-actions
88
= f.button :submit, class: "btn btn-primary"
9-
= link_to t('.cancel', :default => t("helpers.links.cancel")), :back, :class => 'btn'
9+
= link_to_back t('.cancel', :default => t("helpers.links.cancel")), :class => 'btn'

app/views/posts/_form.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
.form-actions
99
= f.button :submit, class: "btn btn-primary"
10-
= link_to t('.cancel', :default => t("helpers.links.cancel")), :back, :class => 'btn'
10+
= link_to_back t('.cancel', :default => t("helpers.links.cancel")), :class => 'btn'

app/views/posts/show.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
%dd= link_to @post.url, @post.url
1212

1313
.form-actions
14-
= link_to t('.back', :default => t("helpers.links.back")), :back, :class => 'btn'
14+
= link_to_back t('.back', :default => t("helpers.links.back")), :class => 'btn'
1515
= link_to t('.edit', :default => t("helpers.links.edit")), edit_post_path(@post), :class => 'btn' if can? :update, @post
1616
= link_to t('.destroy', :default => t("helpers.links.destroy")), post_path(@post), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger' if can? :destroy, @post
1717

app/views/users/_form.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
.form-actions
1111
= f.button :submit, class: "btn btn-primary"
12-
= link_to t('.cancel', :default => t("helpers.links.cancel")), :back, :class => 'btn'
12+
= link_to_back t('.cancel', :default => t("helpers.links.cancel")), :class => 'btn'

app/views/users/show.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%h1= @user.username
44

55
.form-actions
6-
= link_to t('.back', :default => t("helpers.links.back")), :back, :class => 'btn'
6+
= link_to_back t('.back', :default => t("helpers.links.back")), :class => 'btn'
77
= link_to t('.edit', :default => t("helpers.links.edit")), edit_user_path(@user), :class => 'btn' if can? :update, @user
88
= link_to t('.destroy', :default => t("helpers.links.destroy")), user_path(@user), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger' if can? :destroy, @user
99

0 commit comments

Comments
 (0)