Rails在渲染完好后没有任何解释就返回500状态

问题描述 投票:0回答:1

渲染属于另一个动作(:show:edit)的视图来自一个名为:profile的视图。一切都很好,但状态设置为500。

我试过直接渲染它(并得到这个问题)并尝试重定向(但它确实改变了URL ......这不是我想要的)。这种情况都以:html:json格式发生。

这是我的代码:

  # GET /users/profile
  # GET /users/profile.json
  def profile
    @user = current_user
    @profile = @user.profile

    authorize @user

    respond_to do |format|
      format.html { render :edit, status: :edit, location: @user }
      format.json { render :show, status: :show, location: @user }
      # format.json { redirect_to user_path(@user, format: :json), location: @user }
    end
  end

Rails不再以这种方式工作吗? 我一直在互联网上看起来似乎没问题,我不明白。

如果我在respond_to调用它之后设置了一些调试它看起来很好。 我想至少有一些日志跟踪解释问题所在。

以下是一些显示错误的附加日志(来自开发环境):

Started GET "/users/1/edit" for 127.0.0.1 at 2019-03-23 16:00:47 +0100
Processing by UsersController#edit as HTML
  Parameters: {"id"=>"1"}
  User Load (0.9ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Profile Load (0.6ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2  [["user_id", 1], ["LIMIT", 1]]
  CACHE (0.1ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2  [["user_id", 1], ["LIMIT", 1]]
  Rendering users/edit.html.slim within layouts/application
  Rendered devise/registrations/_edit.html.slim (7.2ms)
  Rendered users/_form.html.slim (19.2ms)
  Rendered users/edit.html.slim within layouts/application (24.2ms)
Completed 200 OK in 96ms (Views: 77.9ms | ActiveRecord: 2.1ms)


Started GET "/users/profile" for 127.0.0.1 at 2019-03-23 16:01:00 +0100
Processing by UsersController#profile as HTML
  User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Profile Load (0.4ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2  [["user_id", 1], ["LIMIT", 1]]
  Rendering users/edit.html.slim within layouts/application
  Rendered devise/registrations/_edit.html.slim (7.7ms)
  Rendered users/_form.html.slim (20.5ms)
  Rendered users/edit.html.slim within layouts/application (25.4ms)
Completed 500 Internal Server Error in 85ms (Views: 77.7ms | ActiveRecord: 1.0ms)
ruby-on-rails ruby-on-rails-5
1个回答
1
投票

在你的respond_to块中,你用:status:edit设置:show选项。 这些不是有效的状态代码。

你可以在这里查看清单:Layouts and rendering: the status option

© www.soinside.com 2019 - 2024. All rights reserved.