Skip to content

Instantly share code, notes, and snippets.

@zmoazeni
Created December 11, 2008 18:08
Show Gist options
  • Save zmoazeni/34807 to your computer and use it in GitHub Desktop.
Save zmoazeni/34807 to your computer and use it in GitHub Desktop.
# In Rails Controller
def playlist
@playlist = session[:playlist] = Playlist.new(current_user)
render :layout => false
end
# In RAILS view
xml.instruct! :xml, :version=>"1.0"
xml.playlist do
if @playlist.currently_playing?
xml.currently_playing do
xml.song_in_list @playlist.current_song_in_playlist?
end
end
xml.songs do
@playlist.songs.each do |song|
xml.song do
xml.id song.id
xml.title song.title
xml.artist song.artist
xml.path song.public_path
end
end
end
end
# Would generate
<instruct...(whatever the XML stuff is for it>
<playlist>
<currently_playing>
<song_in_list>12</song_in_list>
</currently_playing>
<songs>
<song>
<id>32</id>
<title>Some cool song</title>
<artist>Foo Fighters</artist>
<path>/path/to/cool_song.mp3</path>
</song>
</songs>
</playlist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment