ruby - Rails get objects in front of dot of a class method -
students = student.limit(3) students.approve() def self.approve # ... end
i want students , use each_with_index, fails. tried self, points out
"nomethoderror: undefined method `each_with_index' #<class:0x00000007a1b920>".
i want objects in front of method, how can this, !
in approve
method have activerecord::relation, need array instead:
def self.approve_all all.each_with_index |user, index| ... end end
class methods in activerecord models can called not on class itself, on activerecord::relation objects.
so example, can call .approve_all
method not directly on class: student.approve_all
, on relation student
class: student.order(name: :asc).limit(10).where(state: "not_approved").approve_all
but think method should @ least named update_all
, , try figure out better solution problem.
Comments
Post a Comment