2012-12-15 26 views
0

我已经添加:远程=>真正的_form.html.erb,现在想知道我怎么能得到它,所以当用户保存页面上的东西时,它会保存并随后到来通知。保存使用Ajax和包括通知 - 导轨

在我的documents_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 

回答

0

你需要编写相应的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 
    }) 
}); 

更多信息可以在这里找到:http://guides.rubyonrails.org/ajax_on_rails.html