go_to_param 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -8
- data/lib/go_to_param/version.rb +1 -1
- data/lib/go_to_param.rb +3 -3
- data/spec/go_to_param_spec.rb +8 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fea100cfef7c5232e51c706f26493d87d58d00d7
|
4
|
+
data.tar.gz: 1151e3917f4c57433a2c2aa9bf5506ab217a1b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19ea749058f98d09dd82ff29d3e530096176b2e618b2f4fe03928bd23257af0f65e1f6057b4f6317fe14892564e20453aaf62cc7d70c91940648b60753eea6f7
|
7
|
+
data.tar.gz: c00954fd5782fcc27411ac6b3271404c986afefc8a19f88b96c7b6bb2f996dcc85f421f898721c8b83fca32758392c52bdcb00d0d114fcb91c7cb4f23f603944
|
data/README.md
CHANGED
@@ -10,15 +10,17 @@ Include in some suitable base controller:
|
|
10
10
|
|
11
11
|
``` ruby
|
12
12
|
class ApplicationController < ActionController::Base
|
13
|
-
include
|
13
|
+
include GoToParam
|
14
14
|
end
|
15
15
|
```
|
16
16
|
|
17
17
|
Now your controllers and views get some methods.
|
18
18
|
|
19
|
-
###
|
19
|
+
### go_to_here_params
|
20
|
+
|
21
|
+
Put the current/requested path in a `{ go_to: "/the_path" }` parameter hash.
|
20
22
|
|
21
|
-
|
23
|
+
Perhaps from a controller:
|
22
24
|
|
23
25
|
``` ruby
|
24
26
|
class ApplicationController < ActionController::Base
|
@@ -30,13 +32,20 @@ class ApplicationController < ActionController::Base
|
|
30
32
|
|
31
33
|
def ensure_authenticated
|
32
34
|
unless authenticated?
|
33
|
-
redirect_to login_path(
|
35
|
+
redirect_to login_path(go_to_here_params)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
```
|
38
40
|
|
39
|
-
|
41
|
+
Or a view:
|
42
|
+
|
43
|
+
``` erb
|
44
|
+
<h1>Show item</h1>
|
45
|
+
<%= link_to("Edit item", edit_item_path(@item, go_to_here_params))
|
46
|
+
```
|
47
|
+
|
48
|
+
This only picks up the requested path if it's a GET, since we can't redirect back to a non-GET later. Otherwise an empty hash is returned.
|
40
49
|
|
41
50
|
### hidden_go_to_tag
|
42
51
|
|
@@ -51,18 +60,18 @@ Pass the `go_to` parameter along with a form.
|
|
51
60
|
</form>
|
52
61
|
```
|
53
62
|
|
54
|
-
###
|
63
|
+
### go_to_params
|
55
64
|
|
56
65
|
Pass the `go_to` parameter along with a link.
|
57
66
|
|
58
67
|
``` erb
|
59
|
-
<%= link_to("Reset password", password_reset_path(
|
68
|
+
<%= link_to("Reset password", password_reset_path(go_to_params)) %>
|
60
69
|
```
|
61
70
|
|
62
71
|
You can pass in additional parameters for the given path:
|
63
72
|
|
64
73
|
``` erb
|
65
|
-
<%= link_to("Reset password", password_reset_path(
|
74
|
+
<%= link_to("Reset password", password_reset_path(go_to_params(email: @email))) %>
|
66
75
|
```
|
67
76
|
|
68
77
|
### go_to_path
|
data/lib/go_to_param/version.rb
CHANGED
data/lib/go_to_param.rb
CHANGED
@@ -3,7 +3,7 @@ require "go_to_param/version"
|
|
3
3
|
module GoToParam
|
4
4
|
def self.included(klass)
|
5
5
|
klass.helper_method :hidden_go_to_tag,
|
6
|
-
:
|
6
|
+
:go_to_params, :go_to_here_params,
|
7
7
|
:go_to_path, :go_to_path_or
|
8
8
|
end
|
9
9
|
|
@@ -11,11 +11,11 @@ module GoToParam
|
|
11
11
|
view_context.hidden_field_tag :go_to, go_to_path
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def go_to_params(other_params = {})
|
15
15
|
{ go_to: go_to_path }.merge(other_params)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def go_to_here_params
|
19
19
|
if request.get?
|
20
20
|
{ go_to: request.fullpath }
|
21
21
|
else
|
data/spec/go_to_param_spec.rb
CHANGED
@@ -33,37 +33,37 @@ describe GoToParam do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe "#
|
36
|
+
describe "#go_to_params" do
|
37
37
|
it "becomes a helper method" do
|
38
|
-
FakeController.helper_methods.should include :
|
38
|
+
FakeController.helper_methods.should include :go_to_params
|
39
39
|
end
|
40
40
|
|
41
41
|
it "includes the go_to parameter" do
|
42
42
|
controller.params = { go_to: "/example", id: "1" }
|
43
43
|
|
44
|
-
controller.
|
44
|
+
controller.go_to_params.should == { go_to: "/example" }
|
45
45
|
end
|
46
46
|
|
47
47
|
it "accepts additional parameters" do
|
48
48
|
controller.params = { go_to: "/example", id: "1" }
|
49
49
|
|
50
|
-
controller.
|
50
|
+
controller.go_to_params(a: "b").should == { go_to: "/example", a: "b" }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe "#
|
54
|
+
describe "#go_to_here_params" do
|
55
55
|
it "becomes a helper method" do
|
56
|
-
FakeController.helper_methods.should include :
|
56
|
+
FakeController.helper_methods.should include :go_to_here_params
|
57
57
|
end
|
58
58
|
|
59
59
|
it "gets the request path as the go_to parameter" do
|
60
60
|
controller.request = double(get?: true, fullpath: "/example")
|
61
|
-
controller.
|
61
|
+
controller.go_to_here_params.should == { go_to: "/example" }
|
62
62
|
end
|
63
63
|
|
64
64
|
it "returns an empty hash for a non-GET request" do
|
65
65
|
controller.request = double(get?: false, fullpath: "/example")
|
66
|
-
controller.
|
66
|
+
controller.go_to_here_params.should == {}
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|