What is the ruby equivalent of python's getattr

前端 未结 4 1129
慢半拍i
慢半拍i 2020-12-10 14:05

I am new to rails and trying to do a little refactoring (putting a partial renderer that lists titles in app/views/shared ) The renderer shows the dates along with the title

4条回答
  •  星月不相逢
    2020-12-10 14:43

    You could add a function to the model like this

    def get_date(date)
      return created_on if date == 'created'
      return updated_on
    end
    

提交回复
热议问题