vendredi 15 juillet 2016

Comma and Dot concurrently on rails in numeric fields

somebody know a trick for use Comma and Dot concurrently in a decimal field, because the international separator is the Dot but in some country is the Comma. i've try with a Before_validation, but i've a lot of problem, sometimes works sometimes doesn't, this is the code:

def update_fields
    [:field_1, :field_2, :field_3].each { |k|
      unless k != nil
        self[k.to_sym] = self.attributes_before_type_cast[k.to_s].gsub(/[.,]/, '.' => '', ',' => '.')
      end
    }
end

thanks in advice.

Aucun commentaire:

Enregistrer un commentaire