Search code examples
ruby-on-railsrubyformsinputformtastic

Custom Formtastic Control with Multiple Parameters


I'm attempting to build a custom control for Formtastic that takes a latitude and a longitude, however, I'm not sure how to go about passing the method names through. Ideally I'd have the following in the semantic_form_for block:

f.input :latitude, :longitude, :as => :location

I've also tried passing with an array:

f.input [:latitude, :longitude], :as => :location

But in both cases, this fails - the first on the number of parameters, the second on the first parameter not being a symbol.

Is there any way of passing two methods into #input that I'm missing?


Solution

  • OK, I've sorted this out by writing a plugin for Formtastic.

    I've added a multi_input function that can take any number of parameters and an (optional) options hash. I've also added a map_input type that outputs the map control and JS (framework agnostic).

    More details at the above link.