Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7633 (closed enhancement: duplicate)

Opened 2 years ago

Last modified 4 months ago

[PATCH] Allow customized regexp for id in map.resources

Reported by: quixoten Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc: vzctl

Description

Currently there is no way to customize the id matching behavior of map.resources. This patch allows you to specify a regular expression for id matching as an option passed to map.resources

i.e. if you had a table of network interfaces that used an ip address as the primary key, you could do

map.resources :network_interfaces, :id => /regexp_for_ip/

Attachments

allow_regexp_for_id_in_map_resources.diff (2.0 kB) - added by quixoten on 02/22/07 23:42:51.
allow_requirements_option_in_map_resources.diff (4.1 kB) - added by quixoten on 02/23/07 18:06:04.
pass_resource_id_requirements_to_member_actions.diff (4.7 kB) - added by quixoten on 05/16/07 23:12:21.

Change History

02/22/07 23:42:51 changed by quixoten

  • attachment allow_regexp_for_id_in_map_resources.diff added.

02/23/07 18:05:10 changed by quixoten

I created another patch that allows the requirements option to be passed to map.resources instead of just a regexp for the id. This allows you to put requirements on the path_prefix parameters as well as the id.

map.resources :service, :path_prefix => /interface/:interface_id,
  :requirements => {:interface_id => /regexp/, :id => /regexp/}

It should be functionally equivalent to the requirements option in map.connect. This patch may also close ticket #6880

02/23/07 18:06:04 changed by quixoten

  • attachment allow_requirements_option_in_map_resources.diff added.

02/25/07 20:13:30 changed by david

  • status changed from new to closed.
  • resolution set to fixed.

Closed by [6232]

04/02/07 01:58:21 changed by Harkins

  • status changed from closed to reopened.
  • type changed from enhancement to defect.
  • resolution deleted.

Actions added to the resource routes with :member do not have the :requirements applied to them. Line 406 of trunk/actionpack/lib/action_controller/resources.rb should also use require_id:

else                  default_options.merge(conditions_for(method)).merge(resource.requirements(require_id)) 

05/16/07 22:34:35 changed by quixoten

I've added a patch (pass_resource_id_requirements_to_member_actions.diff) with a test that fixes the issue presented by Harkins. There might be a better way to go about it, but all tests are passing on my box at the moment.

05/16/07 23:12:21 changed by quixoten

  • attachment pass_resource_id_requirements_to_member_actions.diff added.

05/17/07 16:44:06 changed by quixoten

  • type changed from defect to enhancement.

10/18/07 23:09:29 changed by vzctl

  • cc set to vzctl.

06/06/08 00:01:51 changed by rubyruy

  • status changed from reopened to closed.
  • resolution set to duplicate.