开发者

Js.erb renders only once

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜