Created
August 11, 2012 01:07
-
-
Save pullmonkey/3319690 to your computer and use it in GitHub Desktop.
dynamic select home controller
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/controllers/home_controller.rb | |
class HomeController < ApplicationController | |
def index | |
@genres = Genre.all | |
@artists = Artist.all | |
@songs = Song.all | |
end | |
def update_artists | |
# updates artists and songs based on genre selected | |
genre = Genre.find(params[:genre_id]) | |
# map to name and id for use in our options_for_select | |
@artists = genre.artists.map{|a| [a.name, a.id]}.insert(0, "Select an Artist") | |
@songs = genre.songs.map{|s| [s.title, s.id]}.insert(0, "Select a Song") | |
end | |
def update_songs | |
# updates songs based on artist selected | |
artist = Artist.find(params[:artist_id]) | |
@songs = artist.songs.map{|s| [s.title, s.id]}.insert(0, "Select a Song") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment