String “true” and “false” to boolean

前端 未结 13 877
青春惊慌失措
青春惊慌失措 2020-12-08 18:23

I have a Rails application and I\'m using jQuery to query my search view in the background. There are fields q (search term), start_date, end

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 18:32

    ActiveRecord provides a clean way of doing this.

    def is_true?(string)
      ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(string)
    end
    

    ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES has all of the obvious representations of True values as strings.

提交回复
热议问题