开发者

Js.erb renders only once

开发者 https://www.devze.com 2023-02-20 06:14 出处:网络
I have a Vote button in a hidden Div which is loaded using pirobox.The triggering link is : <div class=\"inliner\"><a href=\"#vid_<%=c.id%>\" rel=\"inline-1000-500\" class=\"pirobox_ga

I have a Vote button in a hidden Div which is loaded using pirobox.The triggering link is :

<div class="inliner"><a href="#vid_<%=c.id%>" rel="inline-1000-500" class="pirobox_gall1"><h5><%=c.title%></h5></a></div>

and in the hidden div, i have the following for my vote button:

<%=button_to 'Vote',vote_path(:format=>:js,:id=>c.id),:remote=>true%>

and in the controller i have:

def vote
        @video=Video.find(params[:id])
        @video.increment!(:votes)

        respond_to do |format|

           format.js  { render 开发者_运维百科:layout=>false }
        end

    end

finally in my js.erb, i have: $('p#success_<%=@video.id%>').fadeIn('slow').delay(1000).fadeOut('slow');

when the trigger link is clicked, the pirobox is loaded with the hidden contents.When i click vote button, the vote is incremented and also the js.erb file is rendered.Everything works fine. But,now i close the pirobox popup.Then trigger it again and click the vote button.The Vote field is incremented, but the js.erb is not rendered :( How should i fix this?


Let's clean a little your code;

Your button:

<%= button_to 'Vote', vote_path(c), :remote => true %>

Your controller:

def vote
  @video = Video.find(params[:id])
  @video.increment!(:votes)
end

your js:

$('#success_<%= @video.id %>').fadeIn('slow').delay(1000).fadeOut('slow');

Now run Firebug and trace your ajax calls via cosole

0

精彩评论

暂无评论...
验证码 换一张
取 消