Rails - Accessing module method in model -


so, i've read all:

but can't make work. here's situation:

i have calc_distance(place1, place2) method , attribute places user model , want define method calc_total_distance in user model.

i want access calc_distance method through utils lib , not load whole utils when using it.

in /lib/utils.rb

module utils   def calc_distance a, b     # blah blah blah   end end 

in /config/application.rb have:

config.autoload_paths += %w(#{config.root}/lib) 

in console, can include utils calc_distance(place1, place2) , works. utils::calc_distance(place1 place2) doesn't work ...

extra-question can ?

then in user.rb model:

  def get_total_distance     # blah blah blah     dist += calc_distance(place1, place2)     # blah blah blah   end 

returns me undefined method 'include' #<user:0x00000006368278>

and

  def get_total_distance     # blah blah blah     dist += utils::calc_distance(place1, place2)     # blah blah blah   end 

returns me undefined method 'calc_distance' utils:module

how can achieve this, knowing prefer second method (which reckon, doesn't load whole utils module ...

class athlete < activerecord::base   include utils   def get_total_distance     # blah blah blah     dist += calc_distance(place1, place2)     # blah blah blah   end end 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -