Changeset 6588
- Timestamp:
- 04/26/07 23:11:31 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/resources.rb (modified) (4 diffs)
- trunk/actionpack/test/controller/resources_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6574 r6588 1 1 *SVN* 2 3 * Added :name_prefix as standard for nested resources [DHH]. WARNING: May be backwards incompatible with your app 4 5 Before: 6 7 map.resources :emails do |emails| 8 emails.resources :comments, :name_prefix => "email_" 9 emails.resources :attachments, :name_prefix => "email_" 10 end 11 12 After: 13 14 map.resources :emails do |emails| 15 emails.resources :comments 16 emails.resources :attachments 17 end 18 19 This does mean that if you intended to have comments_url go to /emails/5/comments, then you'll have to set :name_prefix to nil explicitly. 20 21 * Added :has_many and :has_one for declaring plural and singular resources beneath the current [DHH] 22 23 Before: 24 25 map.resources :notes do |notes| 26 notes.resources :comments 27 notes.resources :attachments 28 notes.resource :author 29 end 30 31 After: 32 33 map.resources :notes, :has_many => [ :comments, :attachments ], :has_one => :author 2 34 3 35 * Added that render :xml will try to call to_xml if it can [DHH]. Makes these work: trunk/actionpack/lib/action_controller/resources.rb
r6485 r6588 235 235 def resources(*entities, &block) 236 236 options = entities.last.is_a?(Hash) ? entities.pop : { } 237 entities.each { |entity| map_resource entity, options.dup, &block}237 entities.each { |entity| map_resource(entity, options.dup, &block) } 238 238 end 239 239 … … 294 294 def resource(*entities, &block) 295 295 options = entities.last.is_a?(Hash) ? entities.pop : { } 296 entities.each { |entity| map_singleton_resource entity, options.dup, &block}296 entities.each { |entity| map_singleton_resource(entity, options.dup, &block) } 297 297 end 298 298 … … 307 307 map_member_actions(map, resource) 308 308 309 map_associations(resource, options) 310 309 311 if block_given? 310 with_options(:path_prefix => resource.nesting_path_prefix, &block)311 end 312 with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix, &block) 313 end 312 314 end 313 315 end … … 322 324 map_member_actions(map, resource) 323 325 326 map_associations(resource, options) 327 324 328 if block_given? 325 with_options(:path_prefix => resource.nesting_path_prefix, &block)329 with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix, &block) 326 330 end 331 end 332 end 333 334 def map_associations(resource, options) 335 Array(options[:has_many]).each do |association| 336 resources(association, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix) 337 end 338 339 Array(options[:has_one]).each do |association| 340 resource(association, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix) 327 341 end 328 342 end trunk/actionpack/test/controller/resources_test.rb
r6485 r6588 10 10 class MessagesController < ResourcesController; end 11 11 class CommentsController < ResourcesController; end 12 class AuthorsController < ResourcesController; end 13 class LogoController < ResourcesController; end 12 14 13 15 class AccountController < ResourcesController; end … … 248 250 end 249 251 end 252 253 def test_resource_has_many_should_become_nested_resources 254 with_routing do |set| 255 set.draw do |map| 256 map.resources :messages, :has_many => [ :comments, :authors ] 257 end 258 259 assert_simply_restful_for :messages 260 assert_simply_restful_for :comments, :path_prefix => 'messages/1/', :options => { :message_id => '1' } 261 assert_simply_restful_for :authors, :path_prefix => 'messages/1/', :options => { :message_id => '1' } 262 end 263 end 264 265 def test_resource_has_one_should_become_nested_resources 266 with_routing do |set| 267 set.draw do |map| 268 map.resources :messages, :has_one => :logo 269 end 270 271 assert_simply_restful_for :messages 272 assert_singleton_restful_for :logo, :path_prefix => 'messages/1/', :options => { :message_id => '1' } 273 end 274 end 250 275 251 276 def test_singleton_resource_with_member_action