public
Description: Rails plugin to quickly make named routes for non-RESTful actions.
Clone URL: git://github.com/ryanb/static_actions.git
Search Repo:
adding root static action methods to remove the controller from the path
Ryan Bates (author)
Thu Apr 03 11:55:25 -0700 2008
commit  061cdf2c98a6ba6fb0c537e11f29268741135bff
tree    d473d6396ca3b6a5c25131b3af20193c71353907
parent  bec446f883bb2741a0f2613f2fde9a04a119fa31
...
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
0
@@ -9,6 +9,19 @@ module StaticActions
0
       send("#{controller}_#{action}", path, :controller => controller.to_s, :action => action.to_s)
0
       send("#{controller}_#{action}_with_format", "#{path}.:format", :controller => controller.to_s, :action => action.to_s)
0
     end
0
+
0
+ def root_static_actions(controller, actions)
0
+ actions.each { |action| root_static_action(controller, action) }
0
+ end
0
+
0
+ def root_static_action(controller, action)
0
+ if action.to_s == 'index'
0
+ root :controller => controller.to_s
0
+ else
0
+ send("#{action}", action.to_s, :controller => controller.to_s, :action => action.to_s)
0
+ send("#{action}_with_format", "#{action.to_s}.:format", :controller => controller.to_s, :action => action.to_s)
0
+ end
0
+ end
0
   end
0
 end
0
 
...
35
36
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
0
@@ -35,4 +35,22 @@ describe StaticActions::MapAdditions do
0
     @map.expects(:foo_bar).with('foo/bar', :controller => 'foo', :action => 'bar')
0
     @map.static_action :foo, :bar
0
   end
0
+
0
+ it "should be able to make a root action which doesn't include controller name" do
0
+ @map.expects(:bar).with('bar', :controller => 'foo', :action => 'bar')
0
+ @map.expects(:bar_with_format).with('bar.:format', :controller => 'foo', :action => 'bar')
0
+ @map.root_static_action :foo, :bar
0
+ end
0
+
0
+ it "should use root named route for index root action" do
0
+ @map.expects(:root).with(:controller => 'foo')
0
+ @map.root_static_action :foo, :index
0
+ end
0
+
0
+ it "should be able to specify multiple root actions" do
0
+ @map.expects(:root).with(:controller => 'foo')
0
+ @map.expects(:bar).with('bar', :controller => 'foo', :action => 'bar')
0
+ @map.expects(:bar_with_format).with('bar.:format', :controller => 'foo', :action => 'bar')
0
+ @map.root_static_actions :foo, [:index, :bar]
0
+ end
0
 end

Comments

    No one has commented yet.