ruby - How to extend a custom rails method? -
i have rails model called projects:
class project < activerecord::base
that has variety of toggle switches, such active, started, paid, etc.
i have method return status in human readable format:
def status return 'pending' if self.pending? return 'started' if self.started return 'in review' if self.in_review? return 'approved' if self.approved return 'active' if self.active end
right have method called status!
returns same information in symbol form, inefficient in mind:
def status return :pending if self.pending? return :started if self.started return :awarded if self.awarded return :in_review if self.in_review? return :approved if self.approved return :active if self.active end
what more status.to_sym
can't figure out how make happen.
any thoughts?
how this:
def status return 'pending' if self.pending? return 'started' if self.started return 'in review' if self.in_review? return 'approved' if self.approved return 'active' if self.active end def status! # added gsub otherwise 'in review' returned ':in review' status.gsub(/\s+/, "_").downcase.to_sym # status.parameterize.underscore.to_sym <- option, rails end
Comments
Post a Comment