state_select and Rails 2.0.2 1

Posted by jcnnghm Tue, 05 Feb 2008 09:23:00 GMT

Because of a change in the workings of Rails 2.0.2, the excellent state_select plugin doesn’t work properly. Fortunately, the fix is really easy. After line 35, enter the following code, value = value(object).

This should give you a new to_state_select_tag, like this:

def to_state_select_tag(country, options, html_options)
  html_options = html_options.stringify_keys
  add_default_name_and_id(html_options)
  value = value(object)
  selected_value = options.has_key?(:selected) ? options[:selected] : value
  content_tag("select", add_options(state_options_for_select(selected_value, country), options, value), html_options)
end

That change got the state_select plugin to work for me under Rails 2.

Update: This has been fixed in the latest version. If you are experiencing this issue, update to the latest version.

Trackbacks

Use the following link to trackback from your own site:
http://littlebitofcode.com/trackbacks?article_id=4

  1. Akhil Bansal Fri, 15 Feb 2008 00:07:29 GMT

    Hi Justin,

    Which version are you using?

    Check the latest code, it is already there in version 13. see http://opensvn.csie.org/stateselect/trunk/lib/stateselect.rb

    regards, Akhil