2010-05-08 21 views
0

之前,我只是用RJS這是真棒但是我習慣把在link_to_remote和這樣的視覺效果開始,我不知道如何之前和遙控器被觸發之後觸發動作。添加視覺效果呈現的行動

拿這個鏈接,例如:

HTML

<span id="<%= "edit_comment_link_#{comment.id.to_s}"%>" style="float:left;"> 
<%= link_to_remote "edit", {:update => "comment_#{comment.id.to_s}", :url => edit_post_comment_path(comment.post, comment), :method => :get}%> | </span> 

控制器:

def edit 
    @comment = Comment.find(params[:id]) 
    respond_to do |format| 
    #format.html render edit_comment_path(@comment) 
    format.js 
    end 
end 

RJS:

page.replace_html "edit_comment_link_#{@comment.id.to_s}", "currently editing | " 

所以是RJS主要是針對後動作呈現視覺效果如此S A微調應放在與call_backs的link_to_remote?這是做事的好方法嗎?

回答

0

這是什麼意思?

<%= link_to_remote '<span>edit</span>', 
     :url => edit_post_comment_path(comment.post, comment), 
     :method => :get, 
     :loading => "Element.show('spinner')", 
     :complete => "Element.hide('spinner')" -%> 

在RJS文件,您可以用疊加效應page.delay /事件:

item = "edit_comment_link_#{@comment.id.to_s}" 
    page.replace_html item, :text => 'currently editing | ' 
    page.visual_effect :fade, item, :duration => 0.5 
    page.delay 0.5 do 
    page.visual_effect :highlight, "other_dom_object", :duration => 0.5 
    end 

上RJS事件的詳細信息在這裏:JavaScriptGenerator API Docs