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?
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.
You can't pass multiple methods to a single input. What you could do is have an accessor on your model called, uh, lat_long
or similar, which could return a string or array or whatever in a format which your location_input recognises and knows how handle.
精彩评论