ruby - Rails store method converts boolean to string -
i have class stores boolean attributes so:
class robot store :options, accessors: [:hairy, :smart] after_initialize :set_defaults private def set_defaults self.hairy ||= false self.smart ||= true end end
i'm trying update these booleans button_to method booleans beingness converted strings in stored hash. default this:
#<robot id: 3, options: {"hairy"=>false,"smart"=>true} >
but this:
<%= button_to 'make hairy', robot_path(@robot, hairy: true), method: :patch %>
turns "hairy" string:
#<robot id: 3, options: {"hairy"=>"true","smart"=>true} >
i need explicitly specify new boolean value, don't want loop through params , toggle! how prevent values becoming strings?
not sure @ point these beingness strings becomes problem in application overwriting default accessors solution?
def hairy super.downcase == 'true' end def smart super.downcase == 'true' end
there's more info in rails docs: http://api.rubyonrails.org/classes/activerecord/store.html
ruby ruby-on-rails-4
No comments:
Post a Comment