2010-09-14 42 views

回答

1

這裏是一個可行的解決方案我想:

在我觀點文件,我用:onSubmit表現出微調:

<% form_for("", @search, 
      :url => {:action => "search"}, 
      :html => {:id => "search_form", 
         :onSubmit => "$('search-loader').show();"}, 
      :remote => true) do |f| %> 

在我搜索行動,我增加了一個行隱藏它:

render :update do |page| 
    ... 
    page << "$('search-loader').hide();" 
end 

它的作品很棒..!

0

好,我使用jQuery,和我做了以下嘗試不顯眼:

</head>標籤前面添加這個,:

= yield :document_ready 

然後在你的application_helper。 rb:

def document_ready(content) 
    html = %{ $(function(){#{content}})} 
    content_for(:document_ready){ javascript_tag(html) } 
    end 

這允許您在加載文檔後加載並運行JavaScript。

在包含表單中添加視圖的頂部:

- document_ready("hide_button_show_spinner('your_button_id')") 

在application.js中

function hide_button_show_spinner(element_id) { 
    $('#'+element_id).bind('click', function() { 
    $('#'+element_id).after("<img src='/path/to/your/spinner.gif' class='ajax_loader' id='"+element_id+"_ajax_loader' style='display: none'/>") 
    $('#'+element_id).hide(); 
    $('#'+element_id+'_ajax_loader').show(); 
    }); 
} 

這將隱藏按鈕,顯示微調一旦按鈕被點擊。你可能需要適應你的具體情況。 然後,您可以顯示按鈕並在JavaScript響應中隱藏微調器(您從ajax請求所調用的動作呈現的.js.erb文件)。