ruby on rails - Cannot call model method from controller -


i've got model named profilelastlocation , i've got controller named singlesaroundcontroller. controller have such action:

  def in_area     box = geocoder::calculations.bounding_box([params[:clat], params[:clng]], params[:distance])     in_area = profilelastlocation.within_bounding_box(box)     render in_area.to_json   end 

when controller action called - error

undefined method `within_bounding_box' #<singlesaroundcontroller:0xb4f107fc> 

when copy rest of code error console - works. bet profilelastlocation model not accessable controller.

my model code is

class profilelastlocation < activerecord::base   include sgltableprefix   belongs_to :user   has_one :profile_setting, through: :user   has_one :profile_mandatory, through: :user   has_one :profile_optional, through: :user    scope :available, -> { joins(:user).where("sgl_users.online = ?", true) }    def self.persons_in_area(clat, clng, distance)     box = geocoder::calculations.bounding_box([clat, clng], distance)     in_area = within_bounding_box(box)       .joins(:profile_mandatory)       .joins(:profile_optional)     in_area   end     geocoded_by :city, :latitude => :latitude, :longitude => :longitude    end 

(i'm using geocode gem). i've tried both define self. method , without self.

also - error shows controller not have given method, while i'm trying call on model, not on controller.

how can access model , methods of given controller?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -