Sha256: ba11e82c552dd622ccf26e22d4b235aee4f6be3eaad792ef018cdf2a472bd2ca
Contents?: true
Size: 920 Bytes
Versions: 43
Compression:
Stored size: 920 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
43 entries across 43 versions & 1 rubygems