# How could I get the routes namespace in the view?

**URL:** <https://www.ruby-forum.com/t/how-could-i-get-the-routes-namespace-in-the-view/192973>\
**Category:** Rails\
**Created:** [August 9, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/how-could-i-get-the-routes-namespace-in-the-view/192973 "2010-08-09T12:12:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xuwenhao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/e99b99/32.png) [@xuwenhao](https://www.ruby-forum.com/u/xuwenhao)\
**Post date:** [August 9, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/how-could-i-get-the-routes-namespace-in-the-view/192973/1 "2010-08-09T12:12:22Z")

</div>

I am currently working on an extension for spree. In this extension,  
we introduce more roles than the current user and admin role. For the  
new role, like a product supplier, we will only let them manage the  
products information the supplier provide. So I created a routes.rb in  
the extension like the following:

map.namespace :supplier do |supplier|  
supplier.resources :products, :member =\> {:clone =\> :get}, :has\_many  
=\> [:product\_properties, :images] do |product|  
product.resources :variants  
product.resources :option\_types, :member =\> { :select  
=\> :get, :remove =\> :get}, :collection =\> {:available  
=\> :get, :selected =\> :get}  
product.resources :taxons, :member =\> {:select =\> :post, :remove  
=\> :post}, :collection =\> {:available =\> :post, :selected =\> :get}  
end  
supplier.resources :orders  
supplier.resources :reports  
end

And I wanted to reuse most of the code in the views and controllers.  
But for the product management page, the code hardcode the url with  
the admin name space as the following:

edit.html.erb for admin/products

\<%= render :partial =\> ‘admin/shared/product\_tabs’, :locals =\>  
{:current =\> “Product Details”} %\>

admin/shared/product\_tabs.html.erb

\<li\<%= ’ class=“active”’ if current == “Product Details” %\>\>  
\<%= link\_to t(“product\_details”), edit\_admin\_product\_url(@product)  
%\>

I am wondering is there any way I could find the current namespace,  
which is supplier to generate the url in a common partial or page?

Like when the admin use the edit.html.erb to render the page, the  
partial url would be ‘admin/shared/product\_tabs’, and  
edit\_admin\_product\_url(@product)

And when the supplier use the edit.html.erb to render the page, the  
partial url would be  
‘supplier/shared/product\_tabs’, and  
edit\_supplier\_product\_url(@product)

Thanks.

---

<div class="post-metadata">

**Author:** ![xuwenhao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/e99b99/32.png) [@xuwenhao](https://www.ruby-forum.com/u/xuwenhao)\
**Post date:** [August 9, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/how-could-i-get-the-routes-namespace-in-the-view/192973/2 "2010-08-09T21:20:40Z")

</div>

Xu Wenhao wrote:

> I am wondering is there any way I could find the current namespace,  
> which is supplier to generate the url in a common partial or page?

I haven’t taken the time to fully think this through, but on the surface  
I would be questioning the need for views to have any direct knowledge  
of routing. Routing is the responsibility of the controller layer.

In a properly partitioned MVC based web application, controllers should  
be responsible for handling requests routed to them by lower level  
framework code (the configured routes in routes.rb in the case of Rails)  
and then render all the views to satisfy the needs of the request. The  
views themselves should have no knowledge of controller  
responsibilities.
