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.