views:

99

answers:

2

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?

A: 

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.

Justin French
Thanks Justin (for your answer and Formtastic :D) - I've been thinking about this, and I reckon going through input is probably the wrong thing to do - it breaks encapsulation if the model needs to present specific methods for view stuff. As far as I can tell, I'd be better to create a new method in SemanticFormBuilder akin to #input and #commit_button - maybe #multi_input?
Mr. Matt
A: 

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.

Mr. Matt