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
Post a Comment