Skip to content

Instantly share code, notes, and snippets.

@pacoguzman
Created November 4, 2011 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pacoguzman/1339018 to your computer and use it in GitHub Desktop.
Save pacoguzman/1339018 to your computer and use it in GitHub Desktop.
ASPGEMS JS BestPractices - RelatedSelects
$('#candidate_form').relatedSelects({
onChangeLoad: '/candidate/profile/update_locations_select',
defaultOptionText: I18n.translate('general.choose_option'),
selects: {
'candidate_profile[country_id]' : {
loadingMessage: I18n.translate('general.loading_provinces')
},
'candidate_profile[province_id]': {
loadingMessage: I18n.translate('general.loading_locations')
},
'candidate_profile[location_id]': {}
}
});
{
<% locations.each_with_index{|location,index| %>
"<%= location.id %>": "<%= location.name %>"
<%= ((locations.size - 1) == index) ? "" : "," %>
<% } %>
}
# GET /candidate/profile/update_locations_select
def update_locations_select
country_id = params[:candidate_profile][:country_id] rescue nil
province_id = params[:candidate_profile][:province_id] rescue nil
if province_id.nil?
provinces = Country.find(country_id).provinces unless country_id.blank?
render :partial => "provinces", :locals => {:provinces => provinces}
else
locations = Province.find(province_id).locations unless province_id.blank?
render :partial => "locations", :locals => {:locations => locations}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment