find_or_redirect 0.1.0 → 0.2.0
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.
- data/README.rdoc +2 -0
- data/lib/find_or_redirect.rb +4 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -73,6 +73,8 @@ The class variable is inferred from the controller name. All options passed to f
|
|
73
73
|
Redirect to a path other than this controller's index
|
74
74
|
|
75
75
|
find_or_redirect :redirect_to => "root_path"
|
76
|
+
find_or_redirect :redirect_to => ":action => :index"
|
77
|
+
find_or_redirect :redirect_to => "'http://www.google.com'"
|
76
78
|
|
77
79
|
==== name
|
78
80
|
|
data/lib/find_or_redirect.rb
CHANGED
@@ -9,11 +9,13 @@ module FindOrRedirect
|
|
9
9
|
redirect_target = opts[:redirect_to] || ":action => :index"
|
10
10
|
klass = (opts[:name] || controller_name).classify
|
11
11
|
finder = opts[:finder] || "#{klass}.find_by_id(params[:id])"
|
12
|
+
filter_name = opts[:filter_name] || "find_#{ instance }_or_redirect"
|
13
|
+
condition = opts[:if] || true
|
12
14
|
|
13
15
|
class_eval <<-RUBYSRC
|
14
|
-
before_filter
|
16
|
+
before_filter :#{ filter_name }, #{ opts.inspect }
|
15
17
|
private
|
16
|
-
def
|
18
|
+
def #{ filter_name }
|
17
19
|
@#{ instance } = #{ finder }
|
18
20
|
unless @#{ instance }
|
19
21
|
redirect_to #{ redirect_target }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: find_or_redirect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Gauthier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-04 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|