String “true” and “false” to boolean

前端 未结 13 761
青春惊慌失措
青春惊慌失措 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:46

    As far as i know there is no built in way of casting strings to booleans, but if your strings only consist of 'true' and 'false' you could shorten your method to the following:

    def to_boolean(str)
      str == 'true'
    end
    

提交回复
热议问题