public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Added a :singular option to resource route building
carllerche (author)
Tue Sep 30 10:48:29 -0700 2008
commit  62bbcc46c28e3921a1efb43b02da4f20b51d080e
tree    9a007532d61fbb479a5a380abe9388c8b2590048
parent  59a2e88f92eaeab86817b933d63d272e02f17213
...
23
24
25
 
26
27
28
...
68
69
70
71
 
72
73
74
...
23
24
25
26
27
28
29
...
69
70
71
 
72
73
74
75
0
@@ -23,6 +23,7 @@ module Merb
0
         #   resource.
0
         # :keys<Array>:
0
         #   A list of the keys to be used instead of :id with the resource in the order of the url.
0
+        # :singular<Symbol>
0
         #
0
         # ==== Block parameters
0
         # next_level<Behavior>:: The child behavior.
0
@@ -68,7 +69,7 @@ module Merb
0
         def resources(name, *args, &block)
0
           name       = name.to_s
0
           options    = extract_options_from_args!(args) || {}
0
-          singular   = Extlib::Inflection.singularize(name)
0
+          singular   = options[:singular] ? options[:singular].to_s : Extlib::Inflection.singularize(name)
0
           klass      = args.first ? args.first.to_s : Extlib::Inflection.classify(singular)
0
           keys       = [ options.delete(:keys) || :id ].flatten
0
           params     = { :controller => options.delete(:controller) || name }
...
138
139
140
 
 
 
 
 
 
 
 
 
141
142
143
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
0
@@ -138,6 +138,15 @@ describe "When generating URLs," do
0
       url(:user_foo, :user_id => 2, :foo => "foo-123").should == "/users/2/foo-123"
0
     end
0
     
0
+    it "should allow the singular name to be set" do
0
+      Merb::Router.prepare do
0
+        resources :blogposts, :singular => :blogpoost
0
+      end
0
+      
0
+      url(:blogposts).should == "/blogposts"
0
+      url(:blogpoost, 1).should == "/blogposts/1"
0
+    end
0
+    
0
   end
0
   
0
   describe "a resource object route" do

Comments

nagybence Tue Sep 30 15:22:15 -0700 2008

“url(:blogpoost, 1)” → “url(:blogposts, 1)” in line 147?

nagybence Tue Sep 30 15:24:11 -0700 2008

Oh, not a typo, sorry, too tired tonight…