redirect_on_back 0.0.1 → 0.0.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDc4YTcyMmNjNzdlZDliYTQyOGI5NTBhYjc3OTdlZTdlMjkzZjQyYg==
4
+ MmQwMzBhNmExOWIwNDIwNDE5ZDI2ODhjMDQ4Mjg5NDM1MjRiOTBkOQ==
5
5
  data.tar.gz: !binary |-
6
- NTliOTA5M2JmZGY4ODg5MzFmMGZkMjViMTI2OGUyNTkxZmJhZjQ3Nw==
6
+ NjI4ZDBmYjI3NThmN2FlNDBjY2FmZWZhMTQyNmRmYjM3NTlkYmJiMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDFlOTUzMzE4OGUzNTNmN2U3YWQ5YmMzZjVlODU0MmZmYWY4MzFlZmNlZjNi
10
- NjRiNTQ1ZmUyMjliMmVlNTY0NGE2ZWRiMmI4NTA5ZDhjNmZiYjA4N2I1OTVh
11
- NjY3YzE0ZTAyM2I1Y2Q2MGQ0NTBjNGI4YmU2NjUyODU2YTI5YTk=
9
+ ZDljZWM1M2Q1ZjlkNjI5ODM0NThiNmIzOTIwMmI5NmVlYzcyNzUyMzljNTgz
10
+ MTVjMjJjZWI4ODExMjkyNGYwMTI0ZWRkOTlmNDQzZWVjZTExNzNiZWY4M2Uw
11
+ OWFhNTdmY2ZkY2QzZWY5N2QyNzcwZDI3ZDVhZThhNmMwMTY0Njk=
12
12
  data.tar.gz: !binary |-
13
- ZTA2ODM4NjhkMzg5OGYwMmUxZjA5ZjU1NTk2MDViYmQ1ZmRhODI5NDE1MTA0
14
- NTI2Y2VjNDRkM2Q1ZjRhM2FkMDkwNjQ2MjI2NjBlMWMzNzE2OGJlNDQ5NTU4
15
- NjM0NmYxNWM4MGE3M2FmZTJhMDk3YWQ1ZmFkYzc5MWMxZjBiNWI=
13
+ YmZjYTUyNzk1ZWI5ZjliNzJkMzM1NGZjM2E5ODI3YmY5ODUxZTQwYTllMTA4
14
+ MTZkMmE5MDE5NGM5M2MwNTlhZTA3NmZmZjBlZmI1ODRlNGRmYmFiNWNiODhl
15
+ NDM5ZGEzYTU3NDMzZTc3ZjdjMzgyODVhMjg5ZjUzM2IxYjI3ODU=
data/README.md CHANGED
@@ -1,24 +1,46 @@
1
- # RedirectOnBack
1
+ # Redirect on Back
2
2
 
3
- TODO: Write a gem description
3
+ Prevent re-submission of a form by redirecting after user hits the back button. For Rails 3.1 and above.
4
4
 
5
- ## Installation
5
+ ### Example Scenario - User Registration
6
+
7
+ 1. User registers by filling in form and hits 'submit'.
8
+ 2. User wants to change one of his details.
9
+ 3. User hits 'back'.
10
+ 4. User changes something and hits 'submit' again.
11
+ 5. Arrrggg... a new User record has been created instead of updating the existing one.
12
+
13
+ ## Installation (Rails 3.1 and higher)
6
14
 
7
15
  Add this line to your application's Gemfile:
8
16
 
9
17
  gem 'redirect_on_back'
10
18
 
11
- And then execute:
19
+ Then execute:
12
20
 
13
21
  $ bundle
14
22
 
15
- Or install it yourself as:
16
23
 
17
- $ gem install redirect_on_back
24
+ And then specify the use of the redirect_on_back
25
+ javascripts in your `application.js`:
26
+
27
+ //= require redirect_on_back
18
28
 
19
29
  ## Usage
20
30
 
21
- TODO: Write usage instructions here
31
+ In your `create` controller actions:
32
+
33
+ ```ruby
34
+ def create
35
+ @user = User.build
36
+ if result = @user.save
37
+ redirect_on_back edit_user_path(@user) # If user hits 'back' he'll be redirected to edit_user_path
38
+ redirect_to @user
39
+ else
40
+ render :action => :new
41
+ end
42
+ end
43
+ ```
22
44
 
23
45
  ## Contributing
24
46
 
@@ -1,9 +1,30 @@
1
- $(function() {
2
- return $('input[name=_usec]').each(function() {
1
+ $(function () {
2
+
3
+ function getCookie(c_name) {
4
+ var c_value = document.cookie;
5
+ var c_start = c_value.indexOf(" " + c_name + "=");
6
+ if (c_start == -1) {
7
+ c_start = c_value.indexOf(c_name + "=");
8
+ }
9
+ if (c_start == -1) {
10
+ c_value = null;
11
+ }
12
+ else {
13
+ c_start = c_value.indexOf("=", c_start) + 1;
14
+ var c_end = c_value.indexOf(";", c_start);
15
+ if (c_end == -1) {
16
+ c_end = c_value.length;
17
+ }
18
+ c_value = unescape(c_value.substring(c_start, c_end));
19
+ }
20
+ return c_value;
21
+ }
22
+
23
+ return $('input[name=_usec]').each(function () {
3
24
  var redirect_path, token;
4
25
  if (token = $(this).val()) {
5
- redirect_path = $.cookie("redirect_" + token);
6
- if (redirect_path) {
26
+ redirect_path = getCookie("redirect_" + token);
27
+ if (redirect_path && redirect_path.length) {
7
28
  $('body').hide();
8
29
  return window.location.href = redirect_path;
9
30
  }
@@ -1,3 +1,3 @@
1
1
  module RedirectOnBack
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redirect_on_back
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yossi-shasho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-05 00:00:00.000000000 Z
11
+ date: 2013-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails