Ruby on Rails Country/State Select Enigma

Ruby on Rails Country/State Select Enigma

It looks like you're assuming that the @person variable is still available from your original action. This could be set up by a filter for the current person but you don't show that in your question.

If you do need to lookup the @person again you'll have to pass the id through in your remote_function I think.

Rails: Undefined local variable or method with Country-State-Select gem

I just learnt from Arvind Vyas the owner of the Country-Select-Select gem in this Stackoverflow answer that the gem depends on the simple_form gem.

So the best bet is to integrate the simple_form gem into the application or look for other alternatives, since the default rails form which I am using will not work for the implementation.

Drop-down for country-states

Try the Carmen plugin:

http://autonomousmachine.com/posts/2009/4/1/carmen-a-rails-plugin-for-geographic-names-and-abbreviations

You can also check this other stackoverflow post:

Ruby on Rails Country/State Select Enigma

Rails: City-state gem f.select issue to getting data states from selected country

When you change the fields from select_tag to f.select you're changing the html id and name of the select elements. f.select will generate an id and name prefixed by the model passed into the form. Your javascript will be looking for an ids like country and state. After changing the elements to use rails form builder f.select tags the ids will be something like famous_person_country and famous_person_state.

Check your html source in the browser (view source) to see what ids have been generated in your form for the select tags and update your cities.js javascript accordingly. It should look something like:

var country = document.getElementById("famous_person_country");
var state = document.getElementById("famous_person_state");

Hope this helps.

how to give country short and state short names in gem 'carmen-rails', '~ 1.0.0'

Try this.

Add new Helper method called region_options_us_and_france :

def region_options_us_and_france
Carmen::Country.all.select{|c| %w{US FR}.include?(c.code)}.map { |r| [r.code, r.code] }
end

def sub_region_options(region)
region.subregions.map { |r| [r.code, r.code] }
end

And update view :

<div class="input-control select country_input" data-role="input-control">
<%= f.select :country, region_options_us_and_france, :prompt => 'Select Country' %>
</div>

change in 'subregion partial'

<%= subregion_select(:account_detail, :state_code, parent_region) %>

with

 <%= f.select :your_field_attr, sub_region_options(country), :prompt => 'Select Sub region' %>

List the time zones for a Country

You can use TimeZone class. You can get all timezones list by:

zones_hash = ActiveSupport::TimeZone::MAPPING

And you can get time zone of any country as the following:

country_zone = ActiveSupport::TimeZone.new("Europe/Skopje")
country_zone.formatted_offset

The output: +01:00 for the above example.



Related Topics



Leave a reply



Submit