从称为:show
的视图中渲染属于另一个操作(:edit
和:profile
)的视图。
一切都很好,但状态设置为500。
我已经尝试过直接渲染它(并解决了这个问题),还尝试了重定向(但是它的确改变了网址……这不是我想要的)。
这会以: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)
答案 0 :(得分:1)
在respond_to
块中,使用:status
和:edit
设置:show
选项。
这些是无效状态代码。
您可以在此处查看列表:Layouts and rendering: the status option