【问题标题】:Error: No template found for XxxController#update, rendering head :no_content错误:找不到 XxxController#update 的模板,渲染头:no_content
【发布时间】:2017-09-04 06:11:35
【问题描述】:

您好,我有以下代码正在开发中。

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)

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

提前感谢您的帮助。

【问题讨论】:

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


    【解决方案1】:

    像这样添加 -

    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'

    【讨论】:

      【解决方案2】:

      这个呢?

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-15
        • 2017-03-27
        • 1970-01-01
        • 2018-02-26
        • 1970-01-01
        相关资源
        最近更新 更多