Created
August 11, 2012 01:08
-
-
Save pullmonkey/3319691 to your computer and use it in GitHub Desktop.
dynamic select home index view
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
# 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