gpt4 book ai didi

javascript - ArgumentError(提供了零位置。无法构建 URI。) - 通过 AJAX 设计重置密码

转载 作者:行者123 更新时间:2023-11-27 22:52:43 29 4
gpt4 key购买 nike

我正在尝试在 Devise 的重置密码页面上实现 ajax。提交的电子邮件很好,但我无法显示任何 javascript 响应,并且还收到 ArgumentError (Nil locationprovided. Can't build URI.) 的错误。

这是我从终端得到的信息:

Devise::Mailer#reset_password_instructions: processed outbound mail in 18.7ms

Sent mail to iamkim@gmail.com (458.2ms)
Date: Mon, 20 Jun 2016 19:06:57 +0100
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: iamkim@gmail.com
Message-ID: <576830c194a0c_5843fd5f0e760c0987e9@iamkim.local.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello iamkim@gmail.com!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><a href="http://localhost:3000/users/password/edit?reset_password_token=6SuAqWSBnKiYZETDdaEJ">Change my password</a></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

Redirected to
Completed 500 Internal Server Error in 532ms (ActiveRecord: 31.6ms)

ArgumentError (Nil location provided. Can't build URI.):
actionpack (4.2.5.2) lib/action_dispatch/routing/polymorphic_routes.rb:200:in `polymorphic_method'
actionpack (4.2.5.2) lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
actionpack (4.2.5.2) lib/action_dispatch/routing/url_for.rb:164:in `url_for'
actionpack (4.2.5.2) lib/action_controller/metal/redirecting.rb:95:in `_compute_redirect_to_location'
turbolinks (2.5.3) lib/turbolinks/xhr_headers.rb:21:in `_compute_redirect_to_location'
actionpack (4.2.5.2) lib/action_controller/metal/redirecting.rb:75:in `redirect_to'
actionpack (4.2.5.2) lib/action_controller/metal/flash.rb:57:in `redirect_to'
actionpack (4.2.5.2) lib/action_controller/metal/instrumentation.rb:64:in `block in redirect_to'
activesupport (4.2.5.2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.5.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.5.2) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.5.2) lib/action_controller/metal/instrumentation.rb:63:in `redirect_to'
responders (2.1.2) lib/action_controller/responder.rb:145:in `redirect_to'
responders (2.1.2) lib/action_controller/responder.rb:205:in `navigation_behavior'
responders (2.1.2) lib/action_controller/responder.rb:172:in `rescue in to_html'
responders (2.1.2) lib/action_controller/responder.rb:170:in `to_html'
responders (2.1.2) lib/action_controller/responder.rb:163:in `respond'
responders (2.1.2) lib/action_controller/responder.rb:156:in `call'
responders (2.1.2) lib/action_controller/respond_with.rb:205:in `respond_with'
devise (3.5.6) app/controllers/devise/passwords_controller.rb:17:in `create'

这是我的代码:

app/views/passwords/new.html.erb

<div class="row row-centered">
<div class="col-md-5 col-centered">
<div class="panel panel-with-header__container col-min col-max">
<h3 class="panel-header panel-header-gray forgot_password_container">
Reset Password
</h3>

<div class="panel-body">

<p>
Enter the email address associated with your account, and we’ll email you a link to reset your password.
</p>

<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }, remote: true) do |f| %>
<%= devise_error_messages! %>

<div class="field form-group">
<%= f.email_field :email, autofocus: true, class: "form-control decorative-input inspectletIgnore", placeholder: "Email address", required: "required" %>
</div>

<hr/>

<div class="actions">
<%= f.submit "Send Reset Link", class: "btn btn-primary" %>
</div>
<% end %>
</div>


</div>
</div>
</div>

app/controllers/passwords_controller.rb

class PasswordsController < Devise::PasswordsController
respond_to :js

def create

self.resource = resource_class.send_reset_password_instructions(resource_params)

respond_to do |format|

@message = ""
if successfully_sent?(resource)
@message = "success"
else
@message = "error"
end

format.html
format.js
end

end

def after_sending_reset_password_instructions_path_for(resource_params)
root_path
end

end

app/views/passwords/create.js.rb

<% if @message == "success" %>
alert('Success!');
<% else %>
alert('Something wrong!');
<% end %>

最佳答案

我可以通过将 devise.rb 中的导航格式更新为:

config.navigational_formats = ['*/*', :html, :js]

关于javascript - ArgumentError(提供了零位置。无法构建 URI。) - 通过 AJAX 设计重置密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37930248/

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