Created
October 6, 2009 19:54
-
-
Save cmilfont/203354 to your computer and use it in GitHub Desktop.
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
#usando o google como host do jquery | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> | |
#código ajax | |
$(document).ready(function() { | |
$("#id_estado").change(function() { | |
$.getJSON("municipios/"+$(this.id)+"/municipios.json", | |
function(data){ | |
$.each(data, function(i, item){ | |
$("<option/>") | |
.attr("id", item.id) | |
.text(item.nome) | |
.appendTo("#id_municipio"); | |
}); | |
}); | |
}); | |
}); | |
#arquivo routes.rb | |
map.municipios_de_um_estado 'municipios_por_estado/:uf/municipios.:format', | |
:controller => "municipios", | |
:action => "municipios_por_estado" | |
#controller | |
class MunicipiosController < ApplicationController | |
def municipios_por_estado | |
@municipios = Municipio.find_all_by_uf params[:uf] | |
respond_to do |format| | |
format.json { | |
render :json => @municipios | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment