我发生了这种非常奇怪的重定向,我无法在控制台中跟踪。这是我看到错误的一个例子:
# this portion makes sense and processing should stop
Rendered recipe_searches/_recipes.html.erb (82.5ms)
Rendered recipe_searches/show.js.erb (87.8ms)
Completed 200 OK in 142ms (Views: 105.6ms | ActiveRecord: 7.9ms)
(0.2ms) BEGIN
(0.2ms) COMMIT
# Somehow I try to find a recipe with id 'thank-you' which does not exist
Started GET "/recipes/thank-you" for ::1 at 2017-07-27 14:19:25 -0400
Processing by RecipesController#show as HTML
Parameters: {"id"=>"thank-you"}
ActiveRecord::SessionStore::Session Load (2.8ms) SELECT "sessions".* FROM "sessions" WHERE "sessions"."session_id" = $1 ORDER BY "sessions"."id" ASC LIMIT 1 [["session_id", "a3279251fee30d7b6fcc9c48e671fc25"]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 528]]
Recipe Load (0.6ms) SELECT "recipes".* FROM "recipes" WHERE "recipes"."slug" = $1 ORDER BY "recipes"."id" ASC LIMIT 1 [["slug", "thank-you"]]
Completed 404 Not Found in 16ms (ActiveRecord: 3.8ms)
这是一个我没有看到错误的时间示例:
Rendered recipe_searches/_recipes.html.erb (89.0ms)
Rendered recipe_searches/show.js.erb (94.6ms)
Completed 200 OK in 157ms (Views: 112.7ms | ActiveRecord: 10.1ms)
(0.2ms) BEGIN
(0.1ms) COMMIT
......就是这样。我根本不知道为什么我的Recipe Controller的节目动作被调用了。更奇怪的是,如果我从/recipes/thank-you
回击并执行相同的操作,我会看到相同的错误。但是,如果我直接修改了网址并将网址从/recipes/thank-you
更改为/recipes
,然后执行相同的操作,则没有错误。
另外,我没有看到" / recipes / thank-you"在我的chrome dev工具中。
还值得注意的是,路径/thank-you
是为某人从不同的控制器填写表单而保留的,并且只有在某些会话变量存在时,他们才会被指示的唯一方式是全部我已经检查过,而且他们不在那里。
编辑:评论中的新信息
我已将问题缩小到我对recipe_searches#create
行动的ajax发布请求。当我在那里发帖时,我将重定向到" / recipes / thank-you"但是,如果我提出标准的邮寄请求,一切都很好。