liftedmedia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-17 11:17 UTC
Sending dynamic variable from view to RJS file (AJAX)
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 the album.id ------------------------------------ VOTE2.rjs page.replace_html ''<%= @albums.id %>'', @albums.reload.votes_count page[:vote_score].visual_effect :highlight ------------------------------------ HTML (VIEW) <td> <span id="<%= albums.id %>"><%= @albums.votes_count %></span> </td> </tr> <tr> <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 %> ------------------------------------ ALBUM CONTROLLER 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 } end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-May-17 12:51 UTC
Re: Sending dynamic variable from view to RJS file (AJAX)
On 5/17/07, liftedmedia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <liftedmedia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > the album.id > > > ------------------------------------ > VOTE2.rjs > > page.replace_html ''<%= @albums.id %>'', @albums.reload.votes_count.rjs files are Ruby, so lose the erb: page.replace_html @albums.id, @albums.reload.votes_count Also, in HTML, ID''s are supposed to start with a letter (http://www.w3.org/TR/html4/types.html#type-id), so I would do something like this: page.replace_html "albums_#{@albums.id}", @albums.reload.votes_count (and a similar construct in the view) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---