Last Updated: February 25, 2016
· mpatrick

Brazillian currency fields with simple_form on Ruby on Rails

Do you need to apply masks on currency fields for Brazilian format? Don't worry, I'll show you a little trick. But, first take a look on a previously post that I wrote about delocalization using I18n::Alchemy, because you'll need this gem

Now that you have the gem and are delocalizing attributes, you need to download the minified version of a javascript with multiple masks inserted already.

Now, call this on your application.js (or somewhere else, maybe a own folder javascript lib):

$(document).ready(function($) {

The next step is create your own currencyinput for simpleform.

class CurrencyInput < SimpleForm::Inputs::Base
  def input
    input_html_options[:type]  ||= "text"

    @builder.text_field(attribute_name, input_html_options)

Now, you just need to call on your simpleformfor this:

= f.input :value, as: :currency

Done this, your application will automatically mask this field to this 0,00 and reach at maximum this value,00

3 Responses
Add your response

The project's URL has changed. Try update it directly to the Github's URL:

over 1 year ago ·

Works like a charm! Thanks!

over 1 year ago ·

What is your way to save this value (with BRL currency) in model?
Why if I submit with value 1,000,000.00, model save with 1

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post a tip