Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
Created August 16, 2012 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pullmonkey/3366572 to your computer and use it in GitHub Desktop.
Save pullmonkey/3366572 to your computer and use it in GitHub Desktop.
erb alternative for the dynamic select box tutorial
# 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