gpt4 book ai didi

ruby-on-rails - Ruby on Rails Controller 重定向不会在 WEBGL 运行时发生

转载 作者:行者123 更新时间:2023-12-04 06:28:51 25 4
gpt4 key购买 nike

我有一个 WEBGL 播放器作为“demo_path”嵌入到 rails 静态页面中,如下所示:

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user, url: signup_path) do |f| %>
<%= render 'shared/error_messages' %>

<%= link_to "mindpass", demo_path, class: "btn btn-lg btn-primary"
%>

<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
</div>
</div>

当用户单击按钮时,它会加载 webgl 模板:
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-
8">
<title>Unity WebGL Player | MindPass_DEMO</title>
<script src="Build/UnityLoader.js"></script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer",
"/assets/Build/MindPass_WEBGL_RY2.json");
</script>
</head>
<body>
<div id="gameContainer" style="width: 90%; height: 90%; position:
absolute; margin: auto;"></div>
</body>
</html>

这将成功加载并实际启动用户 Controller 以保存新用户并启动“redirect_to @users”,如下面的 users_controller 代码所示:
def create
puts "create runs"
#puts params.inspect
@user = User.new(user_params)
if @user.save

puts "user save runs"
log_in @user
puts "second welcome to your vault(users_cont)"
flash[:success] = "Welcome to your vault!"
redirect_to @user
else
puts "render new runs"
render 'new'
end
end

问题是重定向实际上并没有发生。这是尝试的日志,包括重定向:

2018-11-07T05:04:21.897020+00:00 app[web.1]: I,

[2018-11-07T05:04:21.896891 #20] INFO -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] Started POST "/signup" for 76.120.71.73 at 2018-11-07 05:04:21 +0000 2018-11-07T05:04:21.898131+00:00 app[web.1]: I,

[2018-11-07T05:04:21.898049 #20] INFO -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] Processing by UsersController#create as / 2018-11-07T05:04:21.901161+00:00 app[web.1]: I, [2018-11-07T05:04:21.901036 #20] INFO -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] Parameters: {"EMAIL"=>"jakeywtf34@gmail.com", "PASSWORD"=>"[FILTERED]"}

2018-11-07T05:04:21.902007+00:00 app[web.1]: W, [2018-11-07T05:04:21.901922 #20] WARN -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] Can't verify CSRF token authenticity. 2018-11-07T05:04:21.907902+00:00 app[web.1]: create runs

2018-11-07T05:04:21.907965+00:00 app[web.1]: user_params runs

2018-11-07T05:04:21.908031+00:00 app[web.1]: unless state in user_params 2018-11-07T05:04:22.141541+00:00 app[web.1]: D,

[2018-11-07T05:04:22.141393 #20] DEBUG -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] [1m[35m (5.0ms)[0m [1m[35mBEGIN[0m 2018-11-07T05:04:22.145580+00:00 app[web.1]: D, [2018-11-07T05:04:22.145463 #20] DEBUG -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] [1m[36mUser Exists (2.5ms)[0m [1m[34mSELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER($1) LIMIT $2[0m [["email", "jakeywtf34@gmail.com"], ["LIMIT", 1]]

2018-11-07T05:04:22.149368+00:00 app[web.1]: D,

[2018-11-07T05:04:22.149270 #20] DEBUG -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] [1m[35mSQL (2.1ms)[0m [1m[32mINSERT INTO "users" ("email", "created_at", "updated_at", "password_digest") VALUES ($1, $2, $3, $4) RETURNING "id"[0m [["email", "jakeywtf34@gmail.com"], ["created_at", "2018-11-07 05:04:22.146010"], ["updated_at", "2018-11-07 05:04:22.146010"], ["password_digest", "$2a$10$g.RhGJDfl23/zPDeyXEI.OcnsfKfYH3jE4GB7py6/ktMJ3N6y73OW"]]

2018-11-07T05:04:22.153387+00:00 app[web.1]: D,

[2018-11-07T05:04:22.153287 #20] DEBUG -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] [1m[35m (3.5ms)[0m [1m[35mCOMMIT[0m 2018-11-07T05:04:22.153528+00:00 app[web.1]: user save runs 2018-11-07T05:04:22.153618+00:00 app[web.1]: second welcome to your vault(users_cont) 2018-11-07T05:04:22.154318+00:00 app[web.1]: I,

[2018-11-07T05:04:22.154239 #20] INFO -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] Redirected to https://immense-castle-53592.herokuapp.com/users/126

2018-11-07T05:04:22.154585+00:00 app[web.1]: I,

[2018-11-07T05:04:22.154507 #20] INFO -- : [c5de6e8e-58e2-4177-ae17-e1f58fbb65ee] Completed 302 Found in 253ms (ActiveRecord: 13.0ms) 2018-11-07T05:04:22.221827+00:00 app[web.1]: I,

[2018-11-07T05:04:22.221705 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Started GET "/users/126" for 76.120.71.73 at 2018-11-07 05:04:22 +0000 2018-11-07T05:04:22.229274+00:00 app[web.1]: I,

[2018-11-07T05:04:22.229112 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Processing by UsersController#show as / 2018-11-07T05:04:22.230258+00:00 app[web.1]: I,

[2018-11-07T05:04:22.230174 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Parameters: {"id"=>"126"}

2018-11-07T05:04:22.156370+00:00 heroku[router]: at=info method=POST path="/signup" host=immense-castle-53592.herokuapp.com request_id=c5de6e8e-58e2-4177-ae17-e1f58fbb65ee fwd="76.120.71.73" dyno=web.1 connect=1ms service=264ms status=302 bytes=559 protocol=https 2018-11-07T05:04:22.419460+00:00 app[web.1]: D,

[2018-11-07T05:04:22.419270 #6] DEBUG -- : [972376e5-2f11-4985-91fe-53b071181359] [1m[36mUser Load (6.4ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2[0m [["id", 126], ["LIMIT", 1]]

2018-11-07T05:04:22.469417+00:00 app[web.1]: I,

[2018-11-07T05:04:22.469246 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Rendering users/show.html.erb within layouts/application 2018-11-07T05:04:22.470569+00:00 app[web.1]: I,

[2018-11-07T05:04:22.470487 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Rendered users/show.html.erb within layouts/application (1.0ms) 2018-11-07T05:04:22.484847+00:00 app[web.1]: I,

[2018-11-07T05:04:22.484727 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Rendered layouts/_rails_default.html.erb (4.8ms)

2018-11-07T05:04:22.497488+00:00 app[web.1]: I,

[2018-11-07T05:04:22.497361 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Rendered layouts/_shim.html.erb (0.5ms) 2018-11-07T05:04:22.526778+00:00 app[web.1]: I,

[2018-11-07T05:04:22.526644 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Rendered layouts/_header.html.erb (12.1ms) 2018-11-07T05:04:22.540219+00:00 app[web.1]: I,

[2018-11-07T05:04:22.540092 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Rendered layouts/_footer.html.erb (1.0ms) 2018-11-07T05:04:22.541427+00:00 app[web.1]: I,

[2018-11-07T05:04:22.541342 #6] INFO -- : [972376e5-2f11-4985-91fe-53b071181359] Completed 200 OK in 311ms (Views: 83.8ms | ActiveRecord: 103.3ms)

2018-11-07T05:04:22.544712+00:00 heroku[router]: at=info method=GET path="/users/126" host=immense-castle-53592.herokuapp.com request_id=972376e5-2f11-4985-91fe-53b071181359 fwd="76.120.71.73" dyno=web.1 connect=1ms service=324ms status=200 bytes=2692 protocol=https



当我使用下面的普通表单输入执行此操作时,会发生相同的重定向日志,并且它实际上转到用户页面。:
  <%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>

<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>

似乎 WEBGL 正在锁定这件事并拒绝页面实际重定向,即使它应该发生。我错过了什么?

更新 12-6-18:

我注意到当 WEBGL 启动重定向(不成功)时,我在日志中得到了这个:Processing by UsersController#show as/。如果我从一个普通的 html 表单(成功)重定向,我会在日志中得到这个:Processing by UsersController#show as HTML。这是日志中的唯一区别。

我已经测试了以下内容:
  • 使用多个浏览器进行测试以查看它是否特定于某些浏览器
  • 通过将重定向 URL 更改为 https://www.google.co.uk/ 进行测试查看重定向是否成功
  • 添加了一个条件以确保在继续执行脚本之前完成重定向
  • 尝试通过 LocalHost 对 Heroku 进行测试(仍然没有继续)
    可悲的是,这些测试都没有产生任何有说服力的结果。

  • 来自游戏实例的适用 UnityWebRequest C# 代码:
    phase4 = true;
    Invoke ("QuitGame", 10f);
    }
    }

    private IEnumerator Connection ( string name )
    {
    WWWForm form = new WWWForm ();
    form . AddField ( "EMAIL" , _email );
    form . AddField ( "PASSWORD" , passwordUnityEncrypted );
    form . AddField ( "HOST_URL" , absoluteURL );
    form . AddField ( "SIGNUP_PATH" , _url_signup_route );
    form . AddField ( "LOGIN_PATH" , _url_login_route );

    if (absoluteURL == _url_signup){
    UnityWebRequest request = UnityWebRequest . Post (
    _url_signup_route , form );
    yield return request . Send ();
    } else{
    UnityWebRequest request = UnityWebRequest . Post (
    _url_login_route , form );
    yield return request . Send ();
    }

    最佳答案

    我在这里做了一些假设,但我假设 gameInstance 背后的 javascript正在提交发布请求,如果是这种情况,那么我会检查它是否正确处理了重定向。

    更新

    您将需要手动处理重定向(如果我正确理解 Unity 文档)。

    您可以使用 UnityWebRequest.GetResponseHeader 从位置 header 中获取重定向 URL。

    获得位置 URL 后,您应该可以使用 Application.OpenURL如果您使用网络播放器,这将更新浏览器位置。

    private  IEnumerator  Connection ( string  name ) {
    WWWForm form = new WWWForm ();
    form . AddField ( "EMAIL" , _email );
    form . AddField ( "PASSWORD" , passwordUnityEncrypted );
    form . AddField ( "HOST_URL" , absoluteURL );
    form . AddField ( "SIGNUP_PATH" , _url_signup_route );
    form . AddField ( "LOGIN_PATH" , _url_login_route );

    string post_url = "";
    if (absoluteURL == _url_signup) {
    post_url = _url_signup_route;
    } else {
    post_url = _url_login_route;
    }

    UnityWebRequest request = UnityWebRequest.Post(post_url, form);
    yield return request.Send();

    string location = request.GetResponseHeader('location');
    Application.OpenURL(location);
    }

    我的 C# 生锈/不存在,所以那里可能有错误,但这应该给你一个方向。

    关于ruby-on-rails - Ruby on Rails Controller 重定向不会在 WEBGL 运行时发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53183881/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com