Skip to content

Instantly share code, notes, and snippets.

@cleitonfco
Created April 30, 2011 18:38
Show Gist options
  • Save cleitonfco/949858 to your computer and use it in GitHub Desktop.
Save cleitonfco/949858 to your computer and use it in GitHub Desktop.
# routes.rb
match "/admin/by_mark/:id" => "admin/models#by_mark", :as => "by_mark"
# view
<script>
$(function(){
$("#mark").change(function(){
load_model($(this).val());
});
function load_model(mark) {
$.getJSON("<%= by_mark_path(mark) %>", {ajax: 'true'}, function(j) {
var options = '<option value="">Selecione o Modelo</option>';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].model.id + '" '+selected+'>' + j[i].model.name + '</option>';
}
$("#model_id").html(options);
});
});
</script>
collection_select(:state, :id, State.find(:all), value, :name, {:include_blank => "Selecione o Estado", :selected => selected}, {:name => name})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment