This can be fairly easy. There are a bunch of things doing this for you (check out jquery).
I handcoded something a while ago (sorry for the poorly written code). It adds and remove tracks from a playlist
controller:
def add_track
unless session[:admin_playlist_tracks].include?(params[:recording_id])
session[:admin_playlist_tracks] << params[:recording_id]
end
render :partial => "all_tracks"
end
def remove_track
session[:admin_playlist_tracks].delete_if {|x| x.to_s == params[:recording_id].to_s }
render :partial => "all_tracks"
end
container:
<div id="artist_recordings" class="autocomplete_search"></div>
Adding stuff:
<%= link_to_remote "Add",
:url => {:controller => :playlists, :action => :add_track, :recording_id => recording.id},
:update =>"all_tracks",
:complete => visual_effect(:highlight, 'all_tracks') %>
Displaying / removing stuff:
<%session[:admin_playlist_tracks].each do |recording_id|%>
<div style="margin-bottom:4px;">
[<%=link_to_remote "Remove",
:url => {:controller => :playlists, :action => :remove_track, :recording_id => recording_id},
:update =>"all_tracks"%>]
<%recording = Recording.find_by_id(recording_id)%>
<%=recording.song.title%> <br />
by <%=recording.artist.full_name%> (<%=recording.release_year%>)
</div>
<%end%>
This worked with me because I could use session variable. But be careful! In some cases where a user will have various windows with the same form, this will surely break since there will be concurrent access on the session variable.
There are some parts missing because I'm doing some autocomplete on this as well, but I hope this will help you get the big idea.