Skip to Content


Posted on 2 mins read

If you’ve spent time with Rails, you’ll already know that Formtastic is ace, and constructing forms using the SemanticFormBuilder keeps your code neat, and the output sensible and semantic.

More often, I find the need to include a control in my forms that allows the user to find and select a single LatLng, and, up until now, I’ve been adding in hidden fields and creating js that allows me to present a map control.

In an effort to reduce this duplication, I’ve built a Rails plugin for Formtastic that provides a new map_input and multi_input function, which means if you have a lat/lng pair, and you want to let the user fill out these values, all you need do is:

{% highlight erb %} <% semantic_form_for @venue do |f| %> <%= f.multi_input :latitude, :longitude, :as => :map %> <% end %> {% endhighlight %}

Note you’ll also need to include the Google Maps script in your header:

{% highlight html %} {% endhighlight %}


You’ll need Formtastic

Install Maptastic as a plugin:

{% highlight bash %} script/plugin install {% endhighlight %}

Or as a gem:

{% highlight bash %} gem install maptastic-form {% endhighlight %}


This plugin is under development. It’s pretty simple, and patches are very welcome.

The Repo is available on GitHub.