Selecting model based off of route in Rails -


i have polymorphic model discussion. can applied specialty model , program model. routes set as:

resources :programs, :only => :show    resources :discussions, :only => [:show, :create, :destroy, :new] end  resources :specialties    resources :discussions, :only => [:show, :create, :destroy, :new] end 

so, new discussions made either like:

 /specialties/yyyyy/discussions/new  /programs/yyyyyy/discussions/new 

the problem in discussions_controller.rb file. have function:

def new   @object = xxxxx.find(params[:id]) end 

how choose appropriate model form (eg. replace 'xxxxx') , determining discussionable_type. assume parse url, doesn't seem clean. ideas?

given routes, should either have params[:program_id] or params[:specialty_id] (or alike).

this tell use.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -