Hi all, I have a problem with render partial and all that good stuff. I have a link that updates a number (increment rating) when clicked in an Ajaxy-way, without need to refresh. Clicking it for the first time works perfectly, but after it updates the number, if I click it again (it''s supposed to remove rating) - it doesn''t work. Only if I refresh the screen, it works properly (removes the rating). Here''s the code (I tried to remove as much irrelevant stuff as possible): _items_ratings.rhtml: <div id = ... > ... rating here ... .. try to find an existing rating ... <% if @rating && @rating.value == 1 %> <%= link_to_remote (image_tag("/images/arrow-up-d.gif"), :update => this div, :url =>{ :controller => :items, :action => :remove_rating, :id => item.id})%> <% else %> <%= link_to_remote (image_tag("/images/arrow-up.gif"), :update => this div, :url =>{ :controller => :items, :action => :increment_rating, :id => item.id})%> <% end %> </div> items_controller: def increment_rating @item = Item.find(params[:id]) redirect_to :controller => ''rating'', :action => ''increase'', :item_id => @item.id end def remove_rating @item = Item.find(params[:id]) redirect_to :controller => ''rating'', :action => ''remove'', :item_id => @item.id end rating_controller: def increase .. increase rating in the db ... render(:partial => ''items/items_ratings'', :locals => { :item => @item, :id => @item.id }) end def remove .. remove rating from the db ... render(:partial => ''items/items_ratings'', :locals => { :item => @item, :id => @item.id }) end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Not sure if this is the cause of the problem but if the div "<div id = ... > " is inside the partial items_ratings and it is the target of link_to_remote update when you click the link the page is going to look like <div id = ... > <div id = ... > ... rating here ... .. try to find an existing rating ... You may have taken out too much information, whats the div link_to_remote is updating? - Richard On Apr 7, 7:32 am, zavulon <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all, > > I have a problem with render partial and all that good stuff. I have a > link that updates a number (increment rating) when clicked in an > Ajaxy-way, without need to refresh. Clicking it for the first time works > perfectly, but after it updates the number, if I click it again (it''s > supposed to remove rating) - it doesn''t work. Only if I refresh the > screen, it works properly (removes the rating). > > Here''s the code (I tried to remove as much irrelevant stuff as > possible): > > _items_ratings.rhtml: > > <div id = ... > > > ... rating here ... > > .. try to find an existing rating ... > > <% if @rating && @rating.value == 1 %> > <%= link_to_remote (image_tag("/images/arrow-up-d.gif"), :update > => this div, :url =>{ :controller => :items, :action => :remove_rating, > :id => item.id})%> > <% else %> > <%= link_to_remote (image_tag("/images/arrow-up.gif"), :update > => this div, :url =>{ :controller => :items, :action => > :increment_rating, :id => item.id})%> > <% end %> > > </div> > > items_controller: > > def increment_rating > @item = Item.find(params[:id]) > redirect_to :controller => ''rating'', :action => ''increase'', :item_id > => @item.id > end > > def remove_rating > @item = Item.find(params[:id]) > redirect_to :controller => ''rating'', :action => ''remove'', :item_id > => @item.id > end > > rating_controller: > > def increase > > .. increase rating in the db ... > > render(:partial => ''items/items_ratings'', :locals => { :item => > @item, :id => @item.id }) > end > > def remove > > .. remove rating from the db ... > > render(:partial => ''items/items_ratings'', :locals => { :item => > @item, :id => @item.id }) > > end > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Luther wrote:> Not sure if this is the cause of the problem but if the div "<div id > = ... > " is inside the partial items_ratings and it is the target of > link_to_remote update when you click the link the page is going to > look like > <div id = ... > > <div id = ... > > ... rating here ... > > .. try to find an existing rating ... > > You may have taken out too much information, whats the div > link_to_remote is updating? > - RichardAh, that looks to be the case! I see that the div is indeed repeated twice. Here''s a code that names the div (on the main page there''s a listing of items, that''s why I have to dynamically construct the div name): _item.rhtml that contains _items_ratings.rhtml: <% @rating_box_id = ''rating_box_'' + item.id.to_s %> ... <%= render(:partial => ''items_ratings'', :locals => { :item => item, :id => item.id }) -%> Inside _items_ratings.rhtml: <div id = "rating_box_<%= item.id %>"> ... <%= link_to_remote (image_tag("/images/arrow-up-d.gif"), :update=> @rating_box_id, :url =>{ :controller => :items, :action => :remove_rating, :id => item.id})%> ... </div> I think I understand what the problem is... but how do I fix it? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Any ideas, anyone? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---