Class: Muck::HelperController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/muck/helper_controller.rb

Instance Method Summary collapse

Instance Method Details

#load_states_for_countryObject



3
4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/muck/helper_controller.rb', line 3

def load_states_for_country
  country_id = params[:id]
  @states = State.find(:all, :select => 'id, name', :conditions => ["country_id = ?", country_id], :order => "name" )
  label, prompt = Country.build_state_prompts(country_id, true)
  @states.insert(0, State.new(:name => prompt)) if @states.length > 0
  # set cookies so we can remember the last value the user selected
  cookies[:prefered_country_id] = country_id
  respond_to do |format| 
    format.json { render :json => {:states => @states, :label => label, :prompt => prompt}.as_json }
  end
end