2017-04-09 55 views
1

您好,我有以下代碼在開發中工作。錯誤:未找到XxxController#更新的模板,渲染頭:no_content

class SetupController < ApplicationController 
    def update 
    if current_user.update_attributes(user_params) 
     flash[:success] = 'Profile complete' 
     redirect_to user_profile_path(current_user) 
    else 
     flash[:danger] = errors(current_user) 
     redirect_to setup_users(current_user) 
    end 
    end 
end 

get 'setup' => 'setup#edit' 
patch 'setup' => 'setup#update' 

但是在生產中,我得到以下錯誤。該頁面沒有做任何事情。它不重定向。沒有閃光燈。沒什麼。

2017-04-09T01:32:16.299188+00:00 app[web.1]: Processing by SetupController#update as HTML 
2017-04-09T01:32:16.299340+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"9le9H2d1bjNgJyHQDXxuHarF0WOO3acl5jar9txe4Ws2ZaWuzmQ13kQG9HSce3RJ4HksZ5eCQyfuUZPwkDESxw==", "user"=>{"email"=>"[email protected]", "country"=>"AU"}, "commit"=>"Save", "username"=>"joey_knp"} 
2017-04-09T01:32:16.357734+00:00 app[web.1]: No template found for SetupController#update, rendering head :no_content 
2017-04-09T01:32:16.358169+00:00 app[web.1]: Completed 204 No Content in 59ms (ActiveRecord: 0.0ms) 

有誰知道如何解決這個問題?

感謝您提前提供任何幫助。

回答

0

這個怎麼樣?

class SetupController < ApplicationController 
    def update 
    if current_user.update_attributes(user_params) 
     flash[:success] = 'Profile complete' 
     redirect_url = user_profile_path(current_user) 
    else 
     flash[:danger] = errors(current_user) 
     redirect_url = setup_users(current_user) 
    end 
    redirect_to redirect_url 
    end 
end 
0

添加像這樣 -

class SetupController < ApplicationController 
    def update 
    if current_user.update_attributes(user_params) 
     flash[:success] = 'Profile complete' 
     redirect_to user_profile_path(current_user) 
    else 
     flash[:danger] = errors(current_user) 
     redirect_to setup_users(current_user) 
    end 
    respond_to do |format| 
     format.html 
     format.json 
    end 
    end 
end 

,或者你可以簡單地在循環

的末尾添加 render json: {}render 'edit'