Durga Prasad
Durga Prasad

Reputation: 935

find by method return value in rails?

I have a method in model , that method return some value. I want to search by which applications have min_loan = 1000 like, how to ? any one suggest.

Note: Here min_loan is not a column.

Ex: Application.first.min_loan #=> 0

Application.where(:min_loan => 1000)  #=> error

def min_loan
  #return some value
end

Thanks Prasad.

Upvotes: 0

Views: 131

Answers (1)

Thaha kp
Thaha kp

Reputation: 3709

def self.min_loan(val)
  where("loan > ?", val)
end

#assuming that loan is the column name

Then call

Application.min_loan(1000)

It will return applications have min_loan = 1000

Upvotes: 1

Related Questions