Forum: Ruby on Rails Possible RJS Implementation?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
12be02204a4bcaeec2c6c369fe53a45b?d=identicon&s=25 Dave Hoefler (Guest)
on 2006-06-01 23:38
(Received via mailing list)
Hi there,

I have a question regarding updating elements of a two different divs
with
one click. I have two lists. One list holds items that are entered into
a
contest, and the other list holds items that aren't currently in the
contest. One item can only be in one list at a time.

Each list has a partial that renders the items with corresponding
actions.
The items in the current contest list have an action of 'remove from
contest' and the items currently not in a contest have an action of 'add
to
contest'.

When one item is added or removed from their appropriate list I would
like
for it to fade in on the other list.

I currently have the fade out part working fine on both lists when an
item
is selected. It's the dynamically adding a new div id on the other list
that's giving me some issues.

Here's what I currently have for the remove and add to list:

The items that are available:
----------------------------

<div id="elgibile_songs_holder">
    <% for song in @elgibile_songs %>
        <div class="elgibile_song" id="elgibile_id_of_<%= song.id %>">
            <div class="elgibile_title"><%= song.title %></div>

            <div class="elgibile_entered_link">

                <%= link_to_remote h("Submit to this contest"), {
                             :url => { :action => 'contest_enter', :id
=>
@contest, :song_id => song.id },
                            :complete => visual_effect(:fade,
"elgibile_id_of_#{song.id}")} %>

            </div>
        </div>
    <% end %>
</div>


The items that are no available:
---------------------------------
<div id="ineligible_songs_holder">
    <% for song in @ineligible_songs %>
        <div class="ineligible_song" id="id_of_<%= song.id %>">
            <div class="ineligible_title"><%= song.title %></div>

            <div class="ineligible_entered_link">

                <%= link_to_remote h("Remove from this contest"), {
                             :url => { :action => 'contest_unsubmit',
:id =>
@contest, :song_id => song.id },
                            :complete => visual_effect(:fade, "id_of_#{
song.id}", :duration => 1),
                            :confirm => "Are you sure you want to remove
\"#{song.title}\" from the contest?" }%>

            </div>
        </div>
    <% end %>
</div>




The two actions in the methods that handle the corresponding actions
look
like this:

def contest_enter
   #enter2: finish submission of song to contest
   @contest = Contest.find(params[:id])
   @song = Song.find(params[:song_id])
   @member = session[:member_id]
   ContestEntry.find_or_create_by_song_id_and_contest_id(@song.id,@
contest.id)
   @elgibile_songs = ContestEntry.elgibile_songs(@member.id,
@contest.id)
 end

 def contest_unsubmit
   #unsubmit: remove a contest entry
   @contest = Contest.find(params[:id])
   @song = Song.find(params[:song_id])
   c = ContestEntry.find_by_song_id_and_contest_id(@song.id,@contest.id)
   ContestEntry.delete(c.id)
 end


Are there any tutorials that cover what I want to do? I'm thinking I may
have to explore RJS a little bit.

Thank you,
Dave Hoefler
This topic is locked and can not be replied to.