class GenericModel < ActiveRecord::Base
# GenericModel implements many methods that a specific model class can
then
# override in its own definition if needed.
self.abstract_class = true
def some_method(some_param = nil)
# this defined the "default" behavior
end
end
class Project < GenericModel
# if this doesnt declare some_method, it uses the method in
# GenericModel
end
class Scenario < GenericModel
def some_method(some_param = 'sam')
# scenario uses this method, not the one from GenericModel
end
end
class Testcase < GenericModel
# uses the GenericModel version of some_method
end
NOTE: You can also do this with controllers... I have many in my app
that
are little more than:
class ProjectsController < GenericController
def action1_specific_to_this_model
end
def action2_specific_to_this_model
end
end
GenericController does all the standard stuff (index, edit, show, save,
update, delete) by looking at the params[:controller] and doing things
like
@object =
params[:controller].singularize.camelcase.constantize.find(params[:id])
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---