ruby on rails - accessing child namespaced controllers from a parent controller -


recently came across problem problem in accessing namespaced controllers have parent controller in education/educations_controller.rb

class education::educationsscontroller < applicationcontroller    def process_educations      if highschool        controller_to_redirect = 'highschool'      if bacholors        controller_to_redirect = 'bacholors'      else        controller_to_redirect = 'masters'      end     redirect_to :controller => controller_to_redirect, :action => 'process_educations'    end end 

and 3 child controllers education/highschool_controller.rb , education/bacholors_controller.rb , education/masters_controller.rb parametes present in educations_controller.rb passing these controllers

class education::highschoolcontroller < education::educationsscontroller    def proceed_educations      process    end end   class education::bacholorscontroller < education::educationsscontroller    def proceed_educations      process    end end   class education::masterscontroller < education::educationsscontroller    def proceed_educations      process    end end 

and respective views come after in process url becomes long wanted remove controllers url , process irrespective of user taken same url, changed routes.rb

namespace :educations,:path => ''   scope "/educations"    'proceed_educations',to:'educations#proceed_educations'    post 'proceed_educations',to:'educations#proceed_educations'   end   resource :highschool ,:path => ''    'proceed_educations',to:'highschool#proceed_educations'    post 'proceed_educations',to:'highschool#proceed_educations'   end   resource :bacholors ,:path => ''    'proceed_educations',to:'bacholors#proceed_educations'    post 'proceed_educations',to:'bacholors#proceed_educations'   end   resource :masters ,:path => ''    'proceed_educations',to:'masters#proceed_educations'    post 'proceed_educations',to:'masters#proceed_educations'   end end 

this generated same url every controller when try access them in educations_controller.rb redirect same controller highschoolcontroller.

i not getting doing things wrong, please me understand process, or if there better way of doing please suggest.

if want avoid making same urls 2 namespaced controllers, difficult rails understand controller send request.

however, can is, in routes.rb, can eliminate showing controller names , can add space there differentiation, this:

namespace :educations,:path => ''   scope "/educations",:path => ''    'proceed_educations',to:'educations#proceed_educations',:path => ''    post 'proceed_educations',to:'educations#proceed_educations',:path => ''   end   resource :highschool ,:path => ''    'proceed_educations',to:'highschool#proceed_educations'    post 'proceed_educations',to:'highschool#proceed_educations'   end   resource :bacholors ,:path => ' '    'proceed_educations',to:'bacholors#proceed_educations',:path => ''    post 'proceed_educations',to:'bacholors#proceed_educations',:path => ''   end   resource :masters ,:path => '  '    'proceed_educations',to:'masters#proceed_educations',:path => ''    post 'proceed_educations',to:'masters#proceed_educations',:path => ''   end end 

this way, url same spaces.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -