jump_back 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jump_back/engine.rb +1 -0
- data/lib/jump_back/link_back.rb +31 -0
- data/lib/jump_back/options_parser.rb +17 -10
- data/lib/jump_back/path_finder.rb +36 -0
- data/lib/jump_back/redirect_back.rb +2 -6
- data/lib/jump_back/return_to_referer.rb +2 -2
- data/lib/jump_back/urls.rb +28 -0
- data/lib/jump_back/version.rb +1 -1
- data/lib/jump_back.rb +3 -0
- data/spec/controller/application_controller_spec.rb +4 -19
- data/spec/controller/tests_controller_spec.rb +85 -85
- data/spec/dummy/app/controllers/tests_controller.rb +12 -12
- data/spec/dummy/app/views/tests/blank.html.erb +10 -0
- data/spec/dummy/app/views/tests/clear_and_save.html.erb +17 -0
- data/spec/dummy/app/views/tests/save.html.erb +10 -0
- data/spec/dummy/config/routes.rb +11 -59
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +4 -104
- data/spec/dummy/log/test.log +275 -18408
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/features/controller_methods_spec.rb +38 -0
- data/spec/features/view_helpers_spec.rb +87 -0
- metadata +15 -14
- data/lib/jump_back/redirection_determiner.rb +0 -14
- data/lib/jump_back/referer_interpreter.rb +0 -34
- data/spec/dummy/app/views/tests/edit.html.erb +0 -3
- data/spec/dummy/app/views/tests/index.html.erb +0 -6
- data/spec/dummy/app/views/tests/new.html.erb +0 -6
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/features/jump_back_feature_spec.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0af5b300967e7ac035f3ebb0cec0c0d12a48f068
|
4
|
+
data.tar.gz: 05424a881293b19251376c3cf655eab3e989de54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c63a0123fba02897bae16ede59524a275fe62ccf5d675ccc8167bcf9beb84e4f01791c898f7c6590ade0bad45a9b56e3bdf0c663b5890de5dc9208d94a416fb5
|
7
|
+
data.tar.gz: 6ecd0e9ca8aa795a94387134bd01e5239fb69baadbaca72b1f554fc84a658405e5512d0f0facc77111475adca6227711d1365d75449810f7c01f446a0e6fcd96
|
data/lib/jump_back/engine.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module JumpBack
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def link_back(name='back', path=root_path, options={})
|
6
|
+
args = HelpersArguments.parse(name, path, options, root_path)
|
7
|
+
link_to args[:name], PathFinder.new(request, args[:path], args[:jump_back_options]).path, args[:redirect_options]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module HelpersArguments
|
12
|
+
|
13
|
+
def self.parse(name, path, options, root_path)
|
14
|
+
if first_arg_is_path?(name, path, root_path)
|
15
|
+
options = path if path.is_a? Hash
|
16
|
+
path = name
|
17
|
+
name = 'back'
|
18
|
+
end
|
19
|
+
if name.is_a? Hash
|
20
|
+
options = name
|
21
|
+
name = 'back'
|
22
|
+
end
|
23
|
+
options = OptionsParser.new(default: root_path, path: path, options: options)
|
24
|
+
{ name: name, path: options.path, jump_back_options: options.jump_back_options, redirect_options: options.redirect_options }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.first_arg_is_path?(name, path, root_path)
|
28
|
+
Urls.is_url?(name) && (path == root_path || path.is_a?(Hash))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -2,18 +2,25 @@ module JumpBack
|
|
2
2
|
|
3
3
|
class OptionsParser
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
attr_reader :path, :redirect_options, :jump_back_options
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@path = parse(options)[:path]
|
9
|
+
@redirect_options = parse(options)[:redirect_options]
|
10
|
+
@jump_back_options = parse(options)[:jump_back_options]
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(options)
|
14
|
+
return @options if @options
|
15
|
+
|
16
|
+
if options[:path].is_a? Hash
|
17
|
+
options[:options] = options[:path]
|
18
|
+
options[:path] = options[:default]
|
9
19
|
end
|
10
20
|
|
11
|
-
jump_back_options = { offsite: options.delete(:offsite) }
|
12
|
-
|
13
|
-
|
14
|
-
jump_back_options: jump_back_options,
|
15
|
-
path: path
|
16
|
-
}
|
21
|
+
options[:jump_back_options] = { offsite: options[:options].delete(:offsite) }
|
22
|
+
options[:redirect_options] = options.delete(:options)
|
23
|
+
@options = options
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module JumpBack
|
2
|
+
|
3
|
+
class PathFinder
|
4
|
+
attr_reader :path
|
5
|
+
|
6
|
+
def initialize(request, path, options)
|
7
|
+
@uri = Urls.uri(request.env["HTTP_REFERER"])
|
8
|
+
@path = determine_path(request, path, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def redirect_back?(request, options)
|
12
|
+
has_referer?(request) ? is_local?(request, options) ? true : false : false
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_referer?(request)
|
16
|
+
!request.env["HTTP_REFERER"].blank? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_local?(request, options)
|
20
|
+
return true if options[:offsite]
|
21
|
+
!(host && host != request.host)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :uri
|
27
|
+
|
28
|
+
def determine_path(request, path, options)
|
29
|
+
redirect_back?(request, options) ? :back : path
|
30
|
+
end
|
31
|
+
|
32
|
+
def host
|
33
|
+
uri.host if uri
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,14 +1,10 @@
|
|
1
|
-
require 'jump_back/referer_interpreter'
|
2
|
-
require 'jump_back/redirection_determiner'
|
3
|
-
require 'jump_back/options_parser'
|
4
|
-
|
5
1
|
module JumpBack
|
6
2
|
|
7
3
|
module Redirection
|
8
4
|
|
9
5
|
def redirect_back(path=root_path, options={})
|
10
|
-
|
11
|
-
redirect_to
|
6
|
+
options = OptionsParser.new(path: path, options: options, default: root_path)
|
7
|
+
redirect_to PathFinder.new(request, options.path, options.jump_back_options).path, options.redirect_options
|
12
8
|
end
|
13
9
|
end
|
14
10
|
end
|
@@ -9,8 +9,8 @@ module JumpBack
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def return_to_referer(path=root_path, options={})
|
12
|
-
|
13
|
-
session[:jump_back_stored_referer] ? redirect_to(clear_referer,
|
12
|
+
options = OptionsParser.new(path: path, options: options, default: root_path)
|
13
|
+
session[:jump_back_stored_referer] ? redirect_to(clear_referer, options.redirect_options) : redirect_to(options.path, options.redirect_options)
|
14
14
|
end
|
15
15
|
|
16
16
|
def clear_referer
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module JumpBack
|
2
|
+
|
3
|
+
module Urls
|
4
|
+
|
5
|
+
def self.is_url?(string)
|
6
|
+
is_uri?(string) || is_path?(string)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.uri(string)
|
10
|
+
URI.parse string if is_uri? string
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.is_uri?(string)
|
14
|
+
uri = URI.parse string
|
15
|
+
%w( http https ).include? uri.scheme
|
16
|
+
rescue URI::BadURIError
|
17
|
+
false
|
18
|
+
rescue URI::InvalidURIError
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.is_path?(string)
|
23
|
+
!!(Rails.application.routes.recognize_path string)
|
24
|
+
rescue ActionController::RoutingError
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/jump_back/version.rb
CHANGED
data/lib/jump_back.rb
CHANGED
@@ -2,35 +2,20 @@ describe ApplicationController do
|
|
2
2
|
|
3
3
|
describe 'jump_back methods' do
|
4
4
|
|
5
|
-
it '
|
5
|
+
it 'has the redirect_back method' do
|
6
6
|
expect(ApplicationController.new).to respond_to :redirect_back
|
7
7
|
end
|
8
8
|
|
9
|
-
it '
|
9
|
+
it 'has the save_referer method' do
|
10
10
|
expect(ApplicationController.new).to respond_to :save_referer
|
11
11
|
end
|
12
12
|
|
13
|
-
it '
|
13
|
+
it 'has the return_to_referer method' do
|
14
14
|
expect(ApplicationController.new).to respond_to :return_to_referer
|
15
15
|
end
|
16
16
|
|
17
|
-
it '
|
17
|
+
it 'has the clear_referer method' do
|
18
18
|
expect(ApplicationController.new).to respond_to :clear_referer
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
describe 'private jump_back classes' do
|
23
|
-
|
24
|
-
it 'should not have the OptionsParser class' do
|
25
|
-
expect { ApplicationController::OptionsParser.new }.to raise_error
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should not have the RefererInterpreter class' do
|
29
|
-
expect { ApplicationController::RefererInterpreter.new }.to raise_error
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should not have the RedirectionDeterminer class' do
|
33
|
-
expect { ApplicationController::RedirectionDeterminer.new }.to raise_error
|
34
|
-
end
|
35
|
-
end
|
36
21
|
end
|
@@ -2,79 +2,79 @@ describe TestsController, type: :controller do
|
|
2
2
|
|
3
3
|
describe 'redirect_back' do
|
4
4
|
|
5
|
-
it '
|
6
|
-
post :
|
5
|
+
it 'redirects to default with no referer and no arguments' do
|
6
|
+
post :redirect_with_options
|
7
7
|
expect(response).to redirect_to(root_path)
|
8
8
|
end
|
9
9
|
|
10
|
-
it '
|
11
|
-
delete :
|
12
|
-
expect(response).to redirect_to(
|
10
|
+
it 'redirects to the supplied path with no referer' do
|
11
|
+
delete :clear_and_redirect
|
12
|
+
expect(response).to redirect_to(save_path)
|
13
13
|
end
|
14
14
|
|
15
|
-
it '
|
16
|
-
@request.env['HTTP_REFERER'] =
|
17
|
-
post :
|
18
|
-
expect(response).to redirect_to(
|
19
|
-
delete :
|
20
|
-
expect(response).to redirect_to(
|
15
|
+
it 'redirects back with a referer' do
|
16
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
17
|
+
post :redirect_with_options
|
18
|
+
expect(response).to redirect_to(return_with_path_path)
|
19
|
+
delete :clear_and_redirect
|
20
|
+
expect(response).to redirect_to(return_with_path_path)
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
23
|
+
it 'doesn\'t redirect back when the referer is offsite' do
|
24
24
|
@request.env['HTTP_REFERER'] = 'http://rubyonrails.org/'
|
25
|
-
post :
|
25
|
+
post :redirect_with_options
|
26
26
|
expect(response).to redirect_to(root_path)
|
27
|
-
delete :
|
28
|
-
expect(response).to redirect_to(
|
27
|
+
delete :clear_and_redirect
|
28
|
+
expect(response).to redirect_to(save_path)
|
29
29
|
end
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'redirects back when referer is offsite with offsite set to true' do
|
32
32
|
@request.env['HTTP_REFERER'] = 'http://rubyonrails.org/'
|
33
|
-
get :
|
33
|
+
get :offsite_with_path
|
34
34
|
expect(response).to redirect_to('http://rubyonrails.org/')
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
37
|
+
it 'redirects back when referer is offsite with offsite set to true with no path argument' do
|
38
38
|
@request.env['HTTP_REFERER'] = 'http://rubyonrails.org/'
|
39
|
-
get :
|
39
|
+
get :offsite
|
40
40
|
expect(response).to redirect_to('http://rubyonrails.org/')
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
44
|
-
get :
|
45
|
-
expect(response).to redirect_to(
|
46
|
-
get :
|
43
|
+
it 'works normally with no referer if offsite is true' do
|
44
|
+
get :offsite_with_path
|
45
|
+
expect(response).to redirect_to(save_path)
|
46
|
+
get :offsite
|
47
47
|
expect(response).to redirect_to(root_path)
|
48
48
|
end
|
49
49
|
|
50
|
-
it '
|
51
|
-
post :
|
50
|
+
it 'passes additional options to redirect_to' do
|
51
|
+
post :redirect_with_options
|
52
52
|
expect(flash[:notice]).to eq('Created!')
|
53
53
|
expect(response.status).to eq(301)
|
54
54
|
end
|
55
55
|
|
56
|
-
it '
|
56
|
+
it 'passes additional options with offsite set to true with path specified and a referer' do
|
57
57
|
@request.env['HTTP_REFERER'] = 'http://rubyonrails.org/'
|
58
|
-
get :
|
58
|
+
get :offsite_with_path
|
59
59
|
expect(response).to redirect_to('http://rubyonrails.org/')
|
60
60
|
expect(flash[:alert]).to eq('Offsite with default!')
|
61
61
|
end
|
62
62
|
|
63
|
-
it '
|
63
|
+
it 'passes additional options with offsite set to true without path specified and a referer' do
|
64
64
|
@request.env['HTTP_REFERER'] = 'http://rubyonrails.org/'
|
65
|
-
get :
|
65
|
+
get :offsite
|
66
66
|
expect(response).to redirect_to('http://rubyonrails.org/')
|
67
67
|
expect(flash[:alert]).to eq('Offsite without default!')
|
68
68
|
end
|
69
69
|
|
70
|
-
it '
|
71
|
-
get :
|
72
|
-
expect(response).to redirect_to(
|
70
|
+
it 'passes additional options with offsite set to true with path specified and no referer' do
|
71
|
+
get :offsite_with_path
|
72
|
+
expect(response).to redirect_to(save_path)
|
73
73
|
expect(flash[:alert]).to eq('Offsite with default!')
|
74
74
|
end
|
75
75
|
|
76
|
-
it '
|
77
|
-
get :
|
76
|
+
it 'passes additional options with offsite set to true without path specified and no referer' do
|
77
|
+
get :offsite
|
78
78
|
expect(response).to redirect_to(root_path)
|
79
79
|
expect(flash[:alert]).to eq('Offsite without default!')
|
80
80
|
end
|
@@ -82,83 +82,83 @@ describe TestsController, type: :controller do
|
|
82
82
|
|
83
83
|
describe 'save_referer' do
|
84
84
|
|
85
|
-
it '
|
86
|
-
@request.env['HTTP_REFERER'] =
|
87
|
-
get :
|
88
|
-
expect(session[:jump_back_stored_referer]).to eq(
|
85
|
+
it 'saves the referer in the session' do
|
86
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
87
|
+
get :save
|
88
|
+
expect(session[:jump_back_stored_referer]).to eq(return_with_path_path)
|
89
89
|
end
|
90
90
|
|
91
|
-
it '
|
92
|
-
@request.env['HTTP_REFERER'] =
|
93
|
-
get :
|
94
|
-
@request.env['HTTP_REFERER'] =
|
95
|
-
get :
|
96
|
-
expect(session[:jump_back_stored_referer]).to eq(
|
91
|
+
it 'doesn\'t overwrite the referer once saved' do
|
92
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
93
|
+
get :save
|
94
|
+
@request.env['HTTP_REFERER'] = save_path
|
95
|
+
get :save
|
96
|
+
expect(session[:jump_back_stored_referer]).to eq(return_with_path_path)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
describe 'clear_referer' do
|
101
101
|
|
102
|
-
it '
|
103
|
-
@request.env['HTTP_REFERER'] =
|
104
|
-
get :
|
105
|
-
expect(session[:jump_back_stored_referer]).to eq(
|
106
|
-
delete :
|
102
|
+
it 'removes the stored referer' do
|
103
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
104
|
+
get :save
|
105
|
+
expect(session[:jump_back_stored_referer]).to eq(return_with_path_path)
|
106
|
+
delete :clear_and_redirect
|
107
107
|
expect(session[:jump_back_stored_referer]).to be_nil
|
108
108
|
end
|
109
109
|
|
110
|
-
it '
|
111
|
-
@request.env['HTTP_REFERER'] =
|
112
|
-
get :
|
113
|
-
expect(session[:jump_back_stored_referer]).to eq(
|
114
|
-
@request.env['HTTP_REFERER'] =
|
115
|
-
get :
|
116
|
-
expect(session[:jump_back_stored_referer]).to eq(
|
110
|
+
it 'removes the stored referer so it can be written' do
|
111
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
112
|
+
get :save
|
113
|
+
expect(session[:jump_back_stored_referer]).to eq(return_with_path_path)
|
114
|
+
@request.env['HTTP_REFERER'] = save_path
|
115
|
+
get :clear_and_save
|
116
|
+
expect(session[:jump_back_stored_referer]).to eq(save_path)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe 'return_to_referer' do
|
121
|
-
it '
|
122
|
-
@request.env['HTTP_REFERER'] =
|
123
|
-
get :
|
124
|
-
put :
|
125
|
-
expect(response).to redirect_to(
|
126
|
-
end
|
127
|
-
|
128
|
-
it '
|
129
|
-
@request.env['HTTP_REFERER'] =
|
130
|
-
get :
|
131
|
-
post :
|
132
|
-
put :
|
133
|
-
expect(response).to redirect_to(
|
134
|
-
end
|
135
|
-
|
136
|
-
it '
|
137
|
-
@request.env['HTTP_REFERER'] =
|
138
|
-
get :
|
139
|
-
expect(session[:jump_back_stored_referer]).to eq(
|
140
|
-
put :
|
121
|
+
it 'redirects to saved referer' do
|
122
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
123
|
+
get :save
|
124
|
+
put :return_with_options
|
125
|
+
expect(response).to redirect_to(return_with_path_path)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'redirects to saved referer even with actions in between' do
|
129
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
130
|
+
get :save
|
131
|
+
post :redirect_with_options
|
132
|
+
put :return_with_options
|
133
|
+
expect(response).to redirect_to(return_with_path_path)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'deletes the stored referer' do
|
137
|
+
@request.env['HTTP_REFERER'] = return_with_path_path
|
138
|
+
get :save
|
139
|
+
expect(session[:jump_back_stored_referer]).to eq(return_with_path_path)
|
140
|
+
put :return_with_options
|
141
141
|
expect(session[:jump_back_stored_referer]).to be_nil
|
142
142
|
end
|
143
143
|
|
144
|
-
it '
|
145
|
-
put :
|
144
|
+
it 'redirects to default with no referer and no arguments' do
|
145
|
+
put :return_with_options
|
146
146
|
expect(response).to redirect_to(root_path)
|
147
147
|
end
|
148
148
|
|
149
|
-
it '
|
150
|
-
get :
|
151
|
-
expect(response).to redirect_to(
|
149
|
+
it 'redirects to argument with no referer' do
|
150
|
+
get :return_with_path
|
151
|
+
expect(response).to redirect_to(save_path)
|
152
152
|
end
|
153
153
|
|
154
|
-
it '
|
155
|
-
get :
|
154
|
+
it 'passes options to redirect_to with a path specified' do
|
155
|
+
get :return_with_path
|
156
156
|
expect(flash[:alert]).to eq('Go away!')
|
157
157
|
expect(response.status).to eq(301)
|
158
158
|
end
|
159
159
|
|
160
|
-
it '
|
161
|
-
put :
|
160
|
+
it 'passes options to redirect_to without a path specified' do
|
161
|
+
put :return_with_options
|
162
162
|
expect(flash[:notice]).to eq('Updated!')
|
163
163
|
expect(response.status).to eq(302)
|
164
164
|
end
|
@@ -1,38 +1,38 @@
|
|
1
1
|
class TestsController < ApplicationController
|
2
|
-
def
|
2
|
+
def blank
|
3
3
|
end
|
4
4
|
|
5
|
-
def
|
6
|
-
return_to_referer
|
5
|
+
def return_with_path
|
6
|
+
return_to_referer save_path, alert: 'Go away!', status: 301
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def save
|
10
10
|
save_referer
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def redirect_with_options
|
14
14
|
redirect_back notice: 'Created!', status: :moved_permanently
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def clear_and_save
|
18
18
|
clear_referer
|
19
19
|
save_referer
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def return_with_options
|
23
23
|
return_to_referer notice: 'Updated!', status: 302
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def clear_and_redirect
|
27
27
|
clear_referer
|
28
|
-
redirect_back
|
28
|
+
redirect_back save_path
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
redirect_back
|
31
|
+
def offsite_with_path
|
32
|
+
redirect_back save_path, offsite: true, alert: 'Offsite with default!'
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def offsite
|
36
36
|
redirect_back offsite: true, alert: 'Offsite without default!'
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Blank Path
|
2
|
+
<%= form_tag return_with_options_path, method: :put do %>
|
3
|
+
<%= submit_tag 'Put to return_with_options' %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<%= link_to 'Go to save page', save_path %>
|
7
|
+
|
8
|
+
<%= link_back clear_and_save_path %>
|
9
|
+
|
10
|
+
<%= link_back 'A back link', save_path %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Clear and Save Path
|
2
|
+
|
3
|
+
<%= link_to 'Go to save page', save_path %>
|
4
|
+
|
5
|
+
<%= link_back 'Go back from whence you came!' %>
|
6
|
+
|
7
|
+
<%= link_back class: 'red' %>
|
8
|
+
|
9
|
+
<%= link_back 'Just a name!', id: 'just-name', remote: true %>
|
10
|
+
|
11
|
+
<%= link_back save_path, method: :put %>
|
12
|
+
|
13
|
+
<%= link_back 'All options!', save_path, id: 'all-options' %>
|
14
|
+
|
15
|
+
<%= link_back 'http://localhost:3000/tests/clear_and_save', save_path %>
|
16
|
+
|
17
|
+
<%= link_back 'Offsite okay!', offsite: true %>
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,61 +1,13 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
get 'tests/
|
3
|
-
get 'tests/
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# Example of regular route:
|
14
|
-
# get 'products/:id' => 'catalog#view'
|
15
|
-
|
16
|
-
# Example of named route that can be invoked with purchase_url(id: product.id)
|
17
|
-
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
18
|
-
|
19
|
-
# Example resource route (maps HTTP verbs to controller actions automatically):
|
20
|
-
# resources :products
|
21
|
-
|
22
|
-
# Example resource route with options:
|
23
|
-
# resources :products do
|
24
|
-
# member do
|
25
|
-
# get 'short'
|
26
|
-
# post 'toggle'
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# collection do
|
30
|
-
# get 'sold'
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
|
34
|
-
# Example resource route with sub-resources:
|
35
|
-
# resources :products do
|
36
|
-
# resources :comments, :sales
|
37
|
-
# resource :seller
|
38
|
-
# end
|
39
|
-
|
40
|
-
# Example resource route with more complex sub-resources:
|
41
|
-
# resources :products do
|
42
|
-
# resources :comments
|
43
|
-
# resources :sales do
|
44
|
-
# get 'recent', on: :collection
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
|
48
|
-
# Example resource route with concerns:
|
49
|
-
# concern :toggleable do
|
50
|
-
# post 'toggle'
|
51
|
-
# end
|
52
|
-
# resources :posts, concerns: :toggleable
|
53
|
-
# resources :photos, concerns: :toggleable
|
54
|
-
|
55
|
-
# Example resource route within a namespace:
|
56
|
-
# namespace :admin do
|
57
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
58
|
-
# # (app/controllers/admin/products_controller.rb)
|
59
|
-
# resources :products
|
60
|
-
# end
|
2
|
+
get 'tests/offsite_with_path' => 'tests#offsite_with_path', as: 'offsite_with_path'
|
3
|
+
get 'tests/offsite' => 'tests#offsite', as: 'offsite'
|
4
|
+
get 'tests/blank' => 'tests#blank', as: 'blank'
|
5
|
+
get 'tests/return_with_path' => 'tests#return_with_path', as: 'return_with_path'
|
6
|
+
get 'tests/save' => 'tests#save', as: 'save'
|
7
|
+
post 'tests/redirect_with_options' => 'tests#redirect_with_options', as: 'redirect_with_options'
|
8
|
+
get 'tests/clear_and_save' => 'tests#clear_and_save', as: 'clear_and_save'
|
9
|
+
put 'tests/return_with_options' => 'tests#return_with_options', as: 'return_with_options'
|
10
|
+
delete 'tests/clear_and_redirect' => 'tests#clear_and_redirect', as: 'clear_and_redirect'
|
11
|
+
|
12
|
+
root 'tests#blank'
|
61
13
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|