back_to_referer_after_form 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/back_to_referer_after_form.gemspec +58 -0
- data/lib/back_to_referer_after_form.rb +41 -0
- data/test/helper.rb +18 -0
- data/test/test_back_to_referer_after_form.rb +7 -0
- metadata +134 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Alfredo Daniel Rezinovsky
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= back_to_referer_after_form
|
2
|
+
|
3
|
+
Adds a redirect_back_or_to method so after edit/create/destroy it redirects to the FORM referer (usually two steps back from the action) or to the explicit redirection target if there's no place to get back.
|
4
|
+
|
5
|
+
== Warning
|
6
|
+
|
7
|
+
Versions Prior 0.1.6 includes the module in ApplicationController in a bad way breaking the application.
|
8
|
+
DO NOT USE VERSIONS <= 0.1.5
|
9
|
+
|
10
|
+
== Using
|
11
|
+
|
12
|
+
* Include BackToRefererAfterForm in ApplicationController or in your chosen controllers
|
13
|
+
* Use redirect_back_or_to instead redirect_to after succeded save in controllers.
|
14
|
+
|
15
|
+
== Contributing to back_to_referer_after_form
|
16
|
+
|
17
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet (Versions prior to 0.1.2 don't work at all)
|
18
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
19
|
+
* Fork the project
|
20
|
+
* Start a feature/bugfix branch
|
21
|
+
* Commit and push until you are happy with your contribution
|
22
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. (I don't do test, don't know how to. I'm a rails newbie)
|
23
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
24
|
+
|
25
|
+
== Copyright
|
26
|
+
|
27
|
+
Copyright (c) 2011 Alfredo Daniel Rezinovsky. See LICENSE.txt for
|
28
|
+
further details.
|
29
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "back_to_referer_after_form"
|
18
|
+
gem.homepage = "http://github.com/alfrenovsky/back_to_referer_after_form"
|
19
|
+
gem.license = "GPL"
|
20
|
+
gem.summary = %Q{Redirects to the form referer after save/destroy}
|
21
|
+
gem.description = %Q{Adds a redirect_back_or_to method so after edit/create/destroy it redirects to the FORM referer (usually two steps back from the action) or to the explicit redirection target if there's no place to get back.}
|
22
|
+
gem.email = "alfredo@rezinovsky.com.ar"
|
23
|
+
gem.authors = ["Alfredo Daniel Rezinovsky"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "back_to_referer_after_form #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.6
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{back_to_referer_after_form}
|
8
|
+
s.version = "0.1.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Alfredo Daniel Rezinovsky}]
|
12
|
+
s.date = %q{2011-08-10}
|
13
|
+
s.description = %q{Adds a redirect_back_or_to method so after edit/create/destroy it redirects to the FORM referer (usually two steps back from the action) or to the explicit redirection target if there's no place to get back.}
|
14
|
+
s.email = %q{alfredo@rezinovsky.com.ar}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"back_to_referer_after_form.gemspec",
|
27
|
+
"lib/back_to_referer_after_form.rb",
|
28
|
+
"test/helper.rb",
|
29
|
+
"test/test_back_to_referer_after_form.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/alfrenovsky/back_to_referer_after_form}
|
32
|
+
s.licenses = [%q{GPL}]
|
33
|
+
s.require_paths = [%q{lib}]
|
34
|
+
s.rubygems_version = %q{1.8.6}
|
35
|
+
s.summary = %q{Redirects to the form referer after save/destroy}
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
42
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
43
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
44
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
47
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
49
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
55
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# This module should be included in ApplicationController (or in any other)
|
2
|
+
#
|
3
|
+
# example:
|
4
|
+
# include "BackToRefererAfterForm"
|
5
|
+
#
|
6
|
+
module BackToRefererAfterForm
|
7
|
+
def self.included(base)
|
8
|
+
# Stores the referer after the new, edit or destroy
|
9
|
+
base.before_filter :store_referer, :only => [:new, :edit, :destroy]
|
10
|
+
|
11
|
+
# Destroy the stored referer after redirecting or if any other action is called in the middle
|
12
|
+
base.before_filter :destroy_stored_referer, :except => [:new, :edit, :destroy, :create, :update]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Stores the http referer into a session variable
|
16
|
+
def store_referer
|
17
|
+
session[:cud_referer] = request.referer
|
18
|
+
end
|
19
|
+
|
20
|
+
# Destroy the stored http referer
|
21
|
+
def destroy_stored_referer
|
22
|
+
session[:cud_referer]=nil
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Redirects the browser to the stored referer. If there's no stored referer will fallback to
|
27
|
+
# the the target specified in options.
|
28
|
+
#
|
29
|
+
# Redirecting <tt>:back</tt> using <tt>redirect_to</tt> will redirect to the <strong>action</strong> referer, which
|
30
|
+
# is the form.
|
31
|
+
#
|
32
|
+
# Redirecting with <tt>redirect_back_or_to :target</tt> will redirect to the <strong>form</strong> referer if possible.
|
33
|
+
# this is userful when calling a form from other controller and want to get back to where you came from after the
|
34
|
+
# update/create/destroy action.
|
35
|
+
#
|
36
|
+
def redirect_back_or_to(options={},response_status={})
|
37
|
+
options=session[:cud_referer] if session && session[:cud_referer]
|
38
|
+
redirect_to(options,response_status)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'back_to_referer_after_form'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: back_to_referer_after_form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alfredo Daniel Rezinovsky
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-10 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :development
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
version_requirements: *id001
|
32
|
+
name: shoulda
|
33
|
+
prerelease: false
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
type: :development
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 23
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
version_requirements: *id002
|
48
|
+
name: bundler
|
49
|
+
prerelease: false
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
type: :development
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 7
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 6
|
61
|
+
- 4
|
62
|
+
version: 1.6.4
|
63
|
+
version_requirements: *id003
|
64
|
+
name: jeweler
|
65
|
+
prerelease: false
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
type: :development
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
version_requirements: *id004
|
78
|
+
name: rcov
|
79
|
+
prerelease: false
|
80
|
+
description: Adds a redirect_back_or_to method so after edit/create/destroy it redirects to the FORM referer (usually two steps back from the action) or to the explicit redirection target if there's no place to get back.
|
81
|
+
email: alfredo@rezinovsky.com.ar
|
82
|
+
executables: []
|
83
|
+
|
84
|
+
extensions: []
|
85
|
+
|
86
|
+
extra_rdoc_files:
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.rdoc
|
89
|
+
files:
|
90
|
+
- .document
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
- Rakefile
|
95
|
+
- VERSION
|
96
|
+
- back_to_referer_after_form.gemspec
|
97
|
+
- lib/back_to_referer_after_form.rb
|
98
|
+
- test/helper.rb
|
99
|
+
- test/test_back_to_referer_after_form.rb
|
100
|
+
homepage: http://github.com/alfrenovsky/back_to_referer_after_form
|
101
|
+
licenses:
|
102
|
+
- GPL
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.8.6
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Redirects to the form referer after save/destroy
|
133
|
+
test_files: []
|
134
|
+
|