Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.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/5/excel/25.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
Javascript 使用Ajax保存并包含Notice-Rails_Javascript_Ruby On Rails_Ruby_Ajax - Fatal编程技术网

Javascript 使用Ajax保存并包含Notice-Rails

Javascript 使用Ajax保存并包含Notice-Rails,javascript,ruby-on-rails,ruby,ajax,Javascript,Ruby On Rails,Ruby,Ajax,我在_form.html.erb中添加了:remote=>true,现在我想知道如何获得它,因此当用户保存页面上的内容时,它会保存,然后出现一个通知 在我的文档_controller.rb中,我有 def create @document = current_user.documents.build(params[:document]) if @document.save redirect_to @document.edit, notice: 'Saved' else

我在_form.html.erb中添加了:remote=>true,现在我想知道如何获得它,因此当用户保存页面上的内容时,它会保存,然后出现一个通知

在我的文档_controller.rb中,我有

def create
  @document = current_user.documents.build(params[:document])

  if @document.save
    redirect_to @document.edit, notice: 'Saved'
  else
    render action: "new"
  end
end

def update
  @document = current_user.documents.find_by_url_id(params[:id])

  if @document.update_attributes(params[:document])
    redirect_to @document, notice: 'Saved'
  else
    render action: "edit"
  end
end

您需要编写适当的JavaScript来使用以下jQuery事件:

ajax:beforeSend
ajax:complete
ajax:success
ajax:error
例如

更多信息可在此处找到:

$(document).ready(
    $(".ajax_rails_link").bind("ajax:success", function(evt, data, status, xhr){
        console.log(data);

        // Display your notice logic goes here
    })
});