Rails 3 Routing and Namespaces

I want to have a name controller called a "portal".

this will be invested resources such as companies and products.

I need routes like:

/portal/:company_id/product/:id for work

I can get

/portal/company/:company_id/product/:idbut would like to remove the "company" in the url

Hope this is understandable. Please keep in mind that I need a portal with module names.

+3
source share
2 answers

I think you could use scopeto achieve what you want. Perhaps like this:

namespace "portal" do
  scope ":company_id" do
    resources :products
  end
end

This will create the following routes:

    portal_products GET    /portal/:company_id/products(.:format)          {:action=>"index", :controller=>"portal/products"}
                    POST   /portal/:company_id/products(.:format)          {:action=>"create", :controller=>"portal/products"}
 new_portal_product GET    /portal/:company_id/products/new(.:format)      {:action=>"new", :controller=>"portal/products"}
edit_portal_product GET    /portal/:company_id/products/:id/edit(.:format) {:action=>"edit", :controller=>"portal/products"}
     portal_product GET    /portal/:company_id/products/:id(.:format)      {:action=>"show", :controller=>"portal/products"}
                    PUT    /portal/:company_id/products/:id(.:format)      {:action=>"update", :controller=>"portal/products"}
                    DELETE /portal/:company_id/products/:id(.:format)      {:action=>"destroy", :controller=>"portal/products"}

Edit: A randomly used resource instead of resources. Fixed.

+7
source

, , , :

match '/portal/:company_id/product/:id', :to => 'companies_products#show'

:to , , . , , rake routes .

0

All Articles