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 は主に、アクションがレンダリングされた後、スピナーなどの視覚効果を link_to_remote に配置するためのものcall_backsですか? これは物事を行う良い方法ですか?

4

1 に答える 1

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

于 2010-05-26T19:06:44.640 に答える