2012-12-15 28 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