Vitalii Khustochka
2010-Jun-22 16:12 UTC
Incorrect path generation if some controller actions are under path prefix: expected behavior or bug?
Imagine I have a simple scaffolded model Order, controller
OrderControllers with all the default views etc.
Then I modify routes to have all actions except index and show be
available under /admin subdirectory:
resources :orders, :only => [:index, :show]
scope ''/admin'' do
resources :orders, :except => [:index, :show]
end
And after that on my index and show pages the following helper
link_to ''Show'', @order
or
link_to ''Show'', order
generate links that look like:
''http://localhost:3000/admin/orders/1''
which is obviously incorrect and leads to Routing Error.
I know how to work around this (I''m using link_to
''Show'', {action =>
''show'', :id => @order}) just wondering this is expected
behavior for
some reason or a bug?
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Vitalii Khustochka
2010-Jun-22 17:16 UTC
Re: Incorrect path generation if some controller actions are under path prefix: expected behavior or bug?
Oh, I found the reason.
When routes are defined and helpers are generated in the
''define_hash_access'' method, the hash access function is named
the
same for show and update actions: hash_for_order_path. So the update
action''s path helper overwrites the show''s one.
I still wonder if it is a bug or a feature...
I can assume it may not RESTful what I did - routing show and update
to different URLs. Maybe according to REST is expected to be GET and
PUT to the same url.
But if specifying {action => ''show'', :id => @order}
produces correct
path, then it seems it is not prohibited to route show and update to
different urls.
Vitalii
On Jun 22, 7:12 pm, Vitalii Khustochka
<xyc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Imagine I have a simple scaffolded model Order, controller
> OrderControllers with all the default views etc.
>
> Then I modify routes to have all actions except index and show be
> available under /admin subdirectory:
>
> resources :orders, :only => [:index, :show]
> scope ''/admin'' do
> resources :orders, :except => [:index, :show]
> end
>
> And after that on my index and show pages the following helper
>
> link_to ''Show'', @order
> or
> link_to ''Show'', order
>
> generate links that look like:
''http://localhost:3000/admin/orders/1''
> which is obviously incorrect and leads to Routing Error.
>
> I know how to work around this (I''m using link_to
''Show'', {action =>
> ''show'', :id => @order}) just wondering this is
expected behavior for
> some reason or a bug?
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.