Created
August 16, 2012 03:56
-
-
Save pullmonkey/3366572 to your computer and use it in GitHub Desktop.
erb alternative for the dynamic select box tutorial
This file contains hidden or 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
# app/views/home/index.html.haml | |
<%= collection_select(nil, :genre_id, @genres, :id, :name, {:prompt => "Select a Genre"}, {:id => 'genres_select'}) %> | |
<br/> | |
<%= collection_select(nil, :artist_id, @artists, :id, :name, {:prompt => "Select an Artist"}, {:id => 'artists_select'}) %> | |
<br/> | |
<%= collection_select(nil, :song_id, @songs, :id, :title, {:prompt => "Select a Song"}, {:id => 'songs_select'}) %> | |
<script> | |
$(document).ready(function() { | |
$('#genres_select').change(function() { | |
$.ajax({ | |
url: "<%= update_artists_path %>", | |
data: { | |
genre_id : $('#genres_select').val() | |
}, | |
dataType: "script" | |
}); | |
}); | |
$('#artists_select').change(function() { | |
$.ajax({ | |
url: "<%= update_songs_path %>", | |
data: { | |
artist_id : $('#artists_select').val() | |
}, | |
dataType: "script" | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment