Forum: Ruby on Rails Sending dynamic variable from view to RJS file (AJAX)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
on 2007-05-17 15:19
(Received via mailing list)
How do I send a dynamic variable (album_id) too an ajax RJS file
copied below?

This works fine with a static span ID but Im not sure how to transfer


page.replace_html '<%= %>', @albums.reload.votes_count
page[:vote_score].visual_effect :highlight


<span id="<%= %>"><%= @albums.votes_count %></span>
           <td id="rankhype">

            <div id="vote_link">

            <% if logged_in? %>
<a href="#" id="hype"><%= link_to_remote 'Hype',
{ :url => { :action => 'vote2', :id => @albums } },
{ :href => url_for(:action => 'vote2', :id => @albums) } %><% else %><
%= link_to 'Hype',
:controller => 'account', :action => 'login' %>
<% end %>


def vote2
   @albums = Albums.find(params[:id])
     @albums.votes.create(:user => @current_user)
       respond_to do |wants|
       wants.html { redirect_to :action => 'index',
       :permalink => @albums.permalink }
     wants.js { render }
Bob S. (Guest)
on 2007-05-17 16:52
(Received via mailing list)
On 5/17/07, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> wrote:
> page.replace_html '<%= %>', @albums.reload.votes_count

.rjs files are Ruby, so lose the erb:

   page.replace_html, @albums.reload.votes_count

Also, in HTML, ID's are supposed to start with a letter
(, so I would do
something like this:

   page.replace_html "albums_#{}", @albums.reload.votes_count

(and a similar construct in the view)
This topic is locked and can not be replied to.