recognize_path

42 views
Skip to first unread message

Andrew Stone

unread,
Aug 4, 2008, 1:36:54 PM8/4/08
to rubyonra...@googlegroups.com
Hello all,

While looking into a issue posted on the Lockdown forum I came across the following:

ActionController::Routing::Routes.recognize_path "/users/1/edit" => {:action=>"1", :controller=>"users", :id=>"edit"}

Notice the :action and :id value swap.

Is this a mis-use of the recognize_path method...In other words, is it intended to be used with named routes only?  Or is this just a simple bug that needs to be fixed?

thanks,
andy

--
Andrew Stone

Michael Koziarski

unread,
Aug 4, 2008, 3:37:50 PM8/4/08
to rubyonra...@googlegroups.com

Technically it might not even be a bug, it seems to be matching on
:controller/:action/:id. What do you have in your routes file?

But even more fundamentally, why are you calling recognize_path
directly? Perhaps there's an easier way?

> thanks,
> andy
>
> --
> Andrew Stone
>
> >
>

--
Cheers

Koz

Andrew Stone

unread,
Aug 4, 2008, 3:49:57 PM8/4/08
to rubyonra...@googlegroups.com

Technically it might not even be a bug, it seems to be matching on
:controller/:action/:id.  What do you have in your routes file?

But even more fundamentally, why are you calling recognize_path
directly? Perhaps there's an easier way?


If there is an easier way, that would be great.

The routes file  contains just a simple map.resources :users.
 
It's being used in lockdown for the case when someone passes in a named route to the link_to method, such as:

link_to "Login", login_path

I need to get the actual path to either grant/deny the ability to show the link.  I was using recognize_path to return the hash related to the named route.

Does that explain it?  Let me know if more info is needed.

thanks,
andy

--
Andrew Stone

Andrew Stone

unread,
Aug 4, 2008, 4:04:09 PM8/4/08
to rubyonra...@googlegroups.com

If there is an easier way, that would be great.

The routes file  contains just a simple map.resources :users.
 
It's being used in lockdown for the case when someone passes in a named route to the link_to method, such as:

link_to "Login", login_path

I need to get the actual path to either grant/deny the ability to show the link.  I was using recognize_path to return the hash related to the named route.

Does that explain it?  Let me know if more info is needed.



To add a little more...

If the request is http://localhost:3000/login

and

map.login, :controller => "sessions", :action => "destroy"

I need to know that /login => {:controller => "sessions", :action => "destroy} when the request is made.  So, it's just not the link_to call.

thanks again,
andy


--
Andrew Stone

Andrew Stone

unread,
Aug 4, 2008, 4:05:05 PM8/4/08
to rubyonra...@googlegroups.com
map.login, :controller => "sessions", :action => "destroy"


ooops. typing too fast:  :action => "new" for login.  doh!

--
Andrew Stone

Michael Koziarski

unread,
Aug 4, 2008, 4:07:54 PM8/4/08
to rubyonra...@googlegroups.com
> If there is an easier way, that would be great.
>
> The routes file contains just a simple map.resources :users.

Does the /users/1/edit url actually *go* to the right place when you access it?

> It's being used in lockdown for the case when someone passes in a named
> route to the link_to method, such as:
>
> link_to "Login", login_path
>
> I need to get the actual path to either grant/deny the ability to show the
> link. I was using recognize_path to return the hash related to the named
> route.
>
> Does that explain it? Let me know if more info is needed.

I assume map.connect ':controller/:action/:id' is either removed or
comes *after* the map.resources call? If it's the other way around
then this if functioning as intended.

> thanks,
> andy
>
> --
> Andrew Stone
>
> >
>

--
Cheers

Koz

Andrew Stone

unread,
Aug 4, 2008, 4:40:16 PM8/4/08
to rubyonra...@googlegroups.com
On Mon, Aug 4, 2008 at 4:07 PM, Michael Koziarski <mic...@koziarski.com> wrote:

> If there is an easier way, that would be great.
>
> The routes file  contains just a simple map.resources :users.

Does the /users/1/edit url actually *go* to the right place when you access it?


Yes it does.
 

> It's being used in lockdown for the case when someone passes in a named
> route to the link_to method, such as:
>
> link_to "Login", login_path
>
> I need to get the actual path to either grant/deny the ability to show the
> link.  I was using recognize_path to return the hash related to the named
> route.
>
> Does that explain it?  Let me know if more info is needed.

I assume map.connect ':controller/:action/:id' is either removed or
comes *after* the map.resources call?  If it's the other way around
then this if functioning as intended.


map.connect ':controller/:action/:id' is at the end of my routes file.  This is the way it should be, right?


--
Andrew Stone

Michael Koziarski

unread,
Aug 6, 2008, 6:57:51 AM8/6/08
to rubyonra...@googlegroups.com
> Yes it does.

Well that's very strange...

> map.connect ':controller/:action/:id' is at the end of my routes file. This
> is the way it should be, right?

The only other thing I can think of is the request method, which is
also something that affects route matching. you may need to provide
recognize_path with more information in the enviroment hash to make
sure it matches correctly. If you can reproduce this in a tiny test
app, and upload it to lighthouse, people may be able to give you a
hand. Similarly if you can make it fail in the routing tests that'd
make things easier.


--
Cheers

Koz

Reply all
Reply to author
Forward
0 new messages