Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 什么';这是另一种选择:before&;:在rails 3中的rails 2.3.*之后?_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 什么';这是另一种选择:before&;:在rails 3中的rails 2.3.*之后?

Ruby on rails 3 什么';这是另一种选择:before&;:在rails 3中的rails 2.3.*之后?,ruby-on-rails-3,Ruby On Rails 3,我在Rails 3中使用远程表单。它工作正常,但我想在ajax请求期间显示/隐藏微调器 在rails 2.3.*中,我们在远程表单中使用:before&:after来显示/隐藏微调器 在Rails 3中我应该怎么做,因为Rails 3的远程形式不包含这样的选项。以下是我尝试过的一个有效解决方案: 在我的视图文件中,我使用:onSubmit显示微调器: <% form_for("", @search, :url => {:action => "sear

我在Rails 3中使用远程表单。它工作正常,但我想在ajax请求期间显示/隐藏微调器

在rails 2.3.*中,我们在远程表单中使用:before&:after来显示/隐藏微调器


在Rails 3中我应该怎么做,因为Rails 3的远程形式不包含这样的选项。

以下是我尝试过的一个有效解决方案:

在我的视图文件中,我使用
:onSubmit
显示微调器:

<% form_for("", @search,  
            :url => {:action => "search"}, 
            :html => {:id => "search_form", 
                      :onSubmit => "$('search-loader').show();"}, 
            :remote => true) do |f|  %>
{:action=>“search”},
:html=>{:id=>“搜索表单”,
:onSubmit=>“$('search-loader').show();”},
:remote=>true)do | f |%>
在我的搜索操作中,我添加了一行来隐藏它:

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

page好吧,我正在使用jQuery,我正在做以下事情,尽量不引人注目:

在您的
标签前面添加此项:

= yield :document_ready
然后在应用程序_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();
  });
}
函数隐藏按钮显示微调器(元素id){
$(“#”+元素_id).bind('click',function(){
$(“#”+元素_id)
$('#'+element_id).hide();
$(“#”+元素_id+“_ajax_loader”).show();
});
}
单击按钮后,这将隐藏按钮并显示微调器。您可能需要根据您的具体情况进行调整。 然后可以在javascript响应中显示按钮并隐藏微调器(通过ajax请求调用的操作渲染的.js.erb文件)