Calling a method inside model

Jean-Baptiste

I am trying to trigger a method from inside the model where it is defined. But I am getting an "undefined method `completed_mission_names'" when I try to start my server. Can anybody help me find what I'm doing wrong ?

class MenteeProfile < ActiveRecord::Base

  # Update trackable attributes with succeeded missions
  MenteeProfile.completed_mission_names

protected

  def last_completed_mission_action
  end

  def self.completed_mission_names
  end
end
Raffael

Simplified to the max, you are trying to do this:

class A
  A.foo
  def self.foo
    puts 'Calling foo!'
  end
end

This does not work because the method foo is not defined when you try to invoke it. You must define it first, then you can call it. Like so:

class B
  def self.foo
    puts 'Calling foo!'
  end
  B.foo
end

You could also call just foo instead of B.foo from within the class definition. You can add the protected keyword anywhere you like, it will not have any impact on class methods whatsoever.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Calling a function inside onRespons method

From Dev

Calling method from one Viewcontroller inside another

From Dev

Calling Activity Method From Inside A Fragment

From Dev

calling main method inside main in java

From Dev

weakSelf on queue calling method that use self inside

From Dev

Calling a method from inside StreamingMarkupBuilder

From Dev

Calling method inside timers timer Elapsedevent

From Dev

Calling a method on a value inside a mutable Option

From Dev

calling static method from inside the class

From Dev

__call__ when calling a method inside the class

From Dev

Calling a method from inside of another class

From Dev

Calling model custom method in controller

From Dev

Calling Custom Method Inside SKSpriteNode Not Working

From Dev

Is declaring a variable inside of calling a method bad practice?

From Dev

(javascript) Calling a method on an object inside an array

From Dev

Calling self inside a method in smalltalk

From Dev

jQuery - Calling function with parameters inside .on() method

From Dev

Calling a static method inside a class in jar file

From Dev

Calling class method inside string format

From Dev

Call method inside of other model

From Dev

jQuery - Calling function with parameters inside .on() method

From Dev

Call a Method Model inside Controller

From Dev

Calling a method inside Activity from BroadcastReceiver

From Dev

Calling a method inside a method

From Dev

weakSelf on queue calling method that use self inside

From Dev

Calling method inside a method in Interface c#

From Dev

C# Calling a Method Inside another Method

From Dev

Rails - Calling a model method in controller

From Dev

Vue - calling a method inside the vue model

Related Related

HotTag

Archive