ruby - Rails how to create a class method self to keep things DRY? -


i repeat code many times. thing changes name in conditions.

find(:all, :conditions => {:name => 'hans'}, :group => 'dato').map(&:klik) 

i trying make class method in model. can keep dry.

i have been trying , not working.

def self.grafdata(name)     find(:all, :conditions => {:name => '(name)'}, :group => 'dato').map(&:klik) end 

error: uninitialized constant actionview::compiledtemplates::lars

i want able write model.grafdata(hans), model.grafdata(lars)

i add function model:

class model   def self.grafdata(name)     where(name: name).group('dato').map(&:klik)   end end 

you can call either of following:

model.grafdata('lars') model.grafdata('hans') 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -