Created
November 4, 2011 09:49
-
-
Save pacoguzman/1339018 to your computer and use it in GitHub Desktop.
ASPGEMS JS BestPractices - RelatedSelects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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]': {} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
<% locations.each_with_index{|location,index| %> | |
"<%= location.id %>": "<%= location.name %>" | |
<%= ((locations.size - 1) == index) ? "" : "," %> | |
<% } %> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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