Adding Custom Input Fields to Simple Form
In a project I am using Simple Form from the guys of PlataformaTec as a Form Builder. At the beginning of the project, I decided to switch from formtastic to this one because I am big fan of what José Valim is doing. I really like his code, and I think that what he writes is always (as far as I know) extendible, usable, and of course, simple to use.
So last week I needed to use a particular kind of input field. We needed to show a box like this one:

Pretty self explanatory, right?
I wanted to be able to write something like this in my view files (in HAML)
1 2 3 | |
So in order to achieve this, we only needed to add this to config/initializers/simple_form_extensions.rb (for example).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
The key part here is to name the class properly, so when you do :as => :my_class, your MyClass gets called automatically.
Simple Form is very well structured, and provides lots of ways to customize its functionality. Check the readme file to see what you can do without having to create a custom input class like SubdomainInput. Also, you can check this week’s railscasts.