2010-10-21 48 views
0

這裏就是我試圖做...Rails 3 - AJAX重定向?從控制器傳遞類要查看AJAX

控制器

def create 
. 
. 
if @project.save 
    format.js { @project } 
end 

end 

查看

window.location = "<%= redirect_to(@project, :notice => 'Project was successfully created.') %>"; 

總之,使用AJAX創建一個項目。當創建完成後,我想將用戶重定向到該項目。

這不工作......如何將項目從控制器傳遞到視圖?

感謝

回答

1

寫下面的代碼上create.js.erb不工作。

redirect_to(@project, :notice => 'Project was successfully created.' 
0

我喜歡:

def create 
    ... 
if @project.save 
    render js: %[window.location.pathname='#{project_path(@project)}'] 
end 
end 
相關問題