on-the-way on-the-way - 5 months ago 8
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
end


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
end

User.my_method?(params)

Answer
def my_method?(params)`

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

User.new.my_method?(params) 

(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)