kristianmandrup / states_select

Rails states selector for various countries and regions, including USA, Canada and Australia and more to come ...
2 stars 1 forks source link

Design Suggestion/Idea #1

Open asanghi opened 13 years ago

asanghi commented 13 years ago

Hi Kristian,

There are other state select plugins in various avatars already existing but i'm sure you've analyzed why they are not suitable any more.

My suggestion is to make this plugin/gem a bit more open and extensible. I think the list of countries and their states should be read from a locale file. en: regions: usa: al: Alabama mi: Missouri

The gem should install this locale file using a generator if the user wants to make or edit their own. The plugin should ideally provide helpers to build select options and simple arrays. This would enable easy of use with other form builder plugins such as formtastic or simple_form or even outside of html forms for example in model validation.

Just a thought.

kristianmandrup commented 13 years ago

Hi :)

Thanks for the great idea!

"The plugin should ideally provide helpers to build select options and simple arrays"

Well, I already have extracted out the arrays of states available now as class methods, fx: Usa::States.names or Canada::Provinces.names.

I agree it should not target the default Rails form builder, but be easy to integrate with the more "cool" ones, such as formtastic et.al.

I will try the generator with locale approach ASAP. Would be glad if you could assist in the effort :)

asanghi commented 13 years ago

No worries, I'll surely help.

Probably need to think and fix the usage DSL first. I'm not sure we should have data specific classes i.e. Usa::States.names or Canada::Province.names but probably something like

WhateverTheGemName.states_for(:usa) => Returns an array of arrays
WhateverTheGemName.regions_for(:canada, options) => Returns an array customized as per options
WhateverTheGemName.states_for(:australia).option_select => Returns an array with options select tags

This DSL would raise an error if the country is not found in the locale file. You could accept more default country data from contributors and include it in the gem or let users define their own country/regions themselves.

Havent thought everything out, just a brain dump.

kristianmandrup commented 13 years ago

I just updated the gem with some infrastructure trying to implement some of your ideas. Feel free to help :)

kristianmandrup commented 13 years ago

Yeah, I like your DSL idea. Feels very natural :) I would be very happy if you could change the design to use this DSL. It's really great that you added a file for India too :) Cheers!