I am looking to replicate a given object function across various model files
As you can see below, the 2 things I need to vary across the model are
1) the “guser” string
2) the self.xxx
SIMPLIFIED CODE SAMPLE:
def self.get_all
statement="SELECT * FROM gusers WHERE"
results = results + self.find_by_sql(["#{statement} #{statements[shard_id]}"])
return results
end
It would be great if you can provide code to help out here – thanks!
you can create a module like this (suggesting gusers is the table to the current model)
And than in you models:
UPDATE:
But what I really would do would look like this:
More information about Conditions can be found here: http://api.rubyonrails.org/classes/ActiveRecord/Base.html
Or even better you can use scopes: