Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
Created August 11, 2012 01:08
Show Gist options
  • Save pullmonkey/3319691 to your computer and use it in GitHub Desktop.
Save pullmonkey/3319691 to your computer and use it in GitHub Desktop.
dynamic select home index view
# 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'})
:javascript
$(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"
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment