on-the-way on-the-way - 2 years ago 84
Ruby Question

How to pass parameter in rails method?

I have the following method that returns true or false:

def my_method?
# do stuff here

The question is, can I pass parameter with above method? How can I achieve this thanks!

I do like this but it won't work:

def my_method?(params)
# do stuff


Answer Source
def my_method?(params)`

will create an instance method, which thus must be called on an instance of your User class eg


(as per the other comment)

If you want to be able to call it on your User class itself, then you must define it as a class method eg:

def self.my_method?(params)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download