ruby on rails - Getting something different than standard nesting resources -


i wondering if possible nest resources differently see.

usually, resources go this:

resources :article   resources :comment  end 

and produces url /article/:article_id/comment [for comment#index, of course]

however, i'm wondering if differently like

/article/comment   [excluding :article_id] 

article have of other normal routes, , comment behave in first example. there way this, keep /comment connected comments_controller, or need relocate of comment methods articles_controller? i'd prefer avoid that, because causes headaches later.

**you're asking why i'd ever need in context. truth is, i'm doing in different context, 1 easier explain.

edit:

the real purpose different example. want controller, 'employee_benefits', regular controller , have regular resources. however, i'd able /employee_benefits/new_type. type of benefit appears in form when creating new employee_benefit. i'd able things /employee_benefits/edit_type[:id], /employee_benefits/delete [well not exactly]

i think namespacing way go, i'm not sure how it.

more edit:

i'm using these resources:

  match '/benefits/new_type' => 'company_benefits#new_type'   match '/benefits/create_type' => 'company_benefits#create_type'   match '/benefits/types' => 'company_benefits#types'   match '/benefits/type' => 'company_benefits#types' 

instead of

  resources :company_benefits, :path => '/benefits', :as => :benefits      <not using line of code>     resources :company_benefit_types     </not using line of code>   end  

you namespace examples , prefix comment routes "/article". create routes want - although encourage think on , make sure removing article id want.

shallow nesting may work - http://guides.rubyonrails.org/routing.html

edit:

it sounds want in rails 2:

resources :company_benefit_types, :path_prefix => "/benefits" 

in rails 3 this:

scope "/benefits"     resources :company_benefit_types end 

check output running bundle exec rake routes see looks like.

   company_benefit_types    /benefits/company_benefit_types(.:format)          company_benefit_types#index                           post   /benefits/company_benefit_types(.:format)          company_benefit_types#create  new_company_benefit_type    /benefits/company_benefit_types/new(.:format)      company_benefit_types#new edit_company_benefit_type    /benefits/company_benefit_types/:id/edit(.:format) company_benefit_types#edit      company_benefit_type    /benefits/company_benefit_types/:id(.:format)      company_benefit_types#show                           put    /benefits/company_benefit_types/:id(.:format)      company_benefit_types#update                           delete /benefits/company_benefit_types/:id(.:format)      company_benefit_types#destroy 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -