Worked like a charm! Thanks a ton.

On Thu, Sep 25, 2008 at 7:42 PM, Ben Bangert <[EMAIL PROTECTED]> wrote:

> On Sep 25, 2008, at 1:23 PM, Trek wrote:
>
>  I'm using Routes 1.10 and seeing some odd behavior when I
>> use .resources where a valid url (either entered by hand or generated
>> by url_for) doesn't match any resources.
>>
>
> map.resource sets up all routes to require specific HTTP methods. This
> means the match won't work unless you have a fake environ indicating whether
> its a HTTP GET, or POST, etc. For example, this is how the resource tests
> are run in Routes:
>
>        m = Mapper()
>        m.resource('person', 'people')
>        m.create_regs(['people'])
>
>        con = request_config()
>        con.mapper = m
>        def test_path(path, method):
>            env = dict(HTTP_HOST='example.com', PATH_INFO=path,
> REQUEST_METHOD=method)
>            con.mapper_dict = {}
>            con.environ = env
>
>        test_path('/people', 'GET')
>        eq_({'controller':'people', 'action':'index'}, con.mapper_dict)
>        test_path('/people.xml', 'GET')
>        eq_({'controller':'people', 'action':'index', 'format':'xml'},
> con.mapper_dict)
>
>
> Setting con.environ internally calls mapper.match, after setting up the
> environ. Alternatively, this will work:
>
> from routes import *
> from routes.util import url_for
>
> m = Mapper()
> m.resource('blog', 'blogs')
>
> m.create_regs(['blogs'])
> m.environ = {'REQUEST_METHOD':'GET'}
>
> So interactively:
> >>> m.match('/blogs')
> {'action': u'index', 'controller': u'blogs'}
> >>> m.match('/blogs/2')
> {'action': u'show', 'controller': u'blogs', 'id': u'2'}
>
> In case you're worried about setting m.environ, note that its a
> thread-local, so setting it from different threads before matching won't be
> a problem.
>
> Cheers,
> Ben

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to