错误:找不到XxxController#update的模板,渲染头:no_content

时间:2017-04-09 01:44:39

标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-5

您好我已经开发了以下代码。

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"=>"joseph@netengine.com.au", "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)

有谁知道如何解决这个问题?

感谢您提前提供任何帮助。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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'

即可