Sha256: e9ad04d588ac45a16d70801b5d38341eb525238e01a3093dabd0af14d25aa842
Contents?: true
Size: 926 Bytes
Versions: 41
Compression:
Stored size: 926 Bytes
Contents
class Hash #this method adds an key/value pair in the pattern of :<name> => [] to the hash #only if the key <name> doesn't already exists. this function is provided #due to http post's lack of providing the checkboxes field when no cb is #selected. I'm pretty sure that this could be moved direcly into the model #or even ActiveRecord. def add_key_for_checkboxes name self[name.to_s] = [] if self.stringify_keys[name.to_s].nil? end def stringify inject({}) do |options, (key, value)| if value.is_a?(Hash) || value.is_a?(Array) options[key.to_s] = value.stringify else options[key.to_s] = value.to_s end options end end def stringify! each do |key, value| delete(key) if value.is_a?(Hash) || value.is_a?(Array) store(key.to_s, value.stringify!) else store(key.to_s, value.to_s) end end end end
Version data entries
41 entries across 41 versions & 1 rubygems