Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ArgumentError(提供的位置为零。可以';t构建URI。)-通过AJAX设计重置密码_Javascript_Ruby On Rails_Ajax_Ruby On Rails 4_Devise - Fatal编程技术网

Javascript ArgumentError(提供的位置为零。可以';t构建URI。)-通过AJAX设计重置密码

Javascript ArgumentError(提供的位置为零。可以';t构建URI。)-通过AJAX设计重置密码,javascript,ruby-on-rails,ajax,ruby-on-rails-4,devise,Javascript,Ruby On Rails,Ajax,Ruby On Rails 4,Devise,我试图在Desive的重置密码页面上实现ajax。提交的电子邮件很好,但我无法显示任何javascript响应,而且我还收到了ArgumentError错误(提供的位置为零。无法构建URI)。 以下是我从终点站得到的信息: Devise::Mailer#reset_password_instructions: processed outbound mail in 18.7ms Sent mail to iamkim@gmail.com (458.2ms) Date: Mon, 20 Jun 2

我试图在Desive的重置密码页面上实现ajax。提交的电子邮件很好,但我无法显示任何javascript响应,而且我还收到了
ArgumentError错误(提供的位置为零。无法构建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'
designe::Mailer#重置密码#说明:在18.7毫秒内处理出站邮件
发送邮件至iamkim@gmail.com(458.2ms)
日期:2016年6月20日星期一19:06:57+0100
发件人:请在配置初始值设定项处更改我-devise@example.com
回复:请在配置初始值设定项处更改我-devise@example.com
致:iamkim@gmail.com
消息ID:
主题:重置密码说明
Mime版本:1.0
内容类型:text/html;
字符集=UTF-8
内容传输编码:7bit
你好iamkim@gmail.com!

有人请求链接以更改您的密码。你可以通过下面的链接来实现这一点

如果您没有请求,请忽略此电子邮件

在访问上面的链接并创建新的链接之前,您的密码不会更改

重定向到 在532ms内完成500个内部服务器错误(ActiveRecord:31.6ms) ArgumentError(提供了零位置。无法生成URI): actionpack(4.2.5.2)lib/action\u dispatch/routing/polymorphic\u routes.rb:200:in'polymorphic\u method' actionpack(4.2.5.2)lib/action\u dispatch/routing/polymorphic\u routes.rb:114:in'polymorphic\u url' actionpack(4.2.5.2)lib/action\u dispatch/routing/url\u for.rb:164:in'url\u for' actionpack(4.2.5.2)lib/action\u controller/metal/redirecting.rb:95:在“计算重定向到位置”中 turbolinks(2.5.3)lib/turbolinks/xhr\u头文件。rb:21:in`“计算\u重定向\u到\u位置” actionpack(4.2.5.2)lib/action\u controller/metal/redirecting.rb:75:in'redirect\u to' actionpack(4.2.5.2)lib/action\u controller/metal/flash.rb:57:in'redirect\u to' actionpack(4.2.5.2)lib/action\u controller/metal/instrumentation.rb:64:in'block in redirect\u 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\u controller/metal/instrumentation.rb:63:in'redirect\u to' 响应程序(2.1.2)lib/action\u controller/responder.rb:145:in'redirect\u to' 响应者(2.1.2)lib/action\u controller/responder.rb:205:in'navigation\u behavior' 响应者(2.1.2)lib/action\u controller/responder.rb:172:in'rescue in_html' 响应者(2.1.2)lib/action\u controller/responder.rb:170:in'to\u html' 响应者(2.1.2)lib/action\u controller/responder.rb:163:in'respond' 响应者(2.1.2)lib/action\u controller/responder.rb:156:in'call' 响应者(2.1.2)lib/action\u controller/respond\u with.rb:205:in'respond\u with' 设计(3.5.6)应用程序/控制器/设计/密码/控制器。rb:17:在“创建”中
这是我的密码:

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> 
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
<% if @message == "success" %>
    alert('Success!');
<% else %>
    alert('Something wrong!');
<% end %>

重置密码

输入与您的帐户关联的电子邮件地址,我们将通过电子邮件向您发送一个链接以重置您的密码。


app/controllers/passwords\u controller.rb

<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> 
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
<% if @message == "success" %>
    alert('Success!');
<% else %>
    alert('Something wrong!');
<% end %>
类密码控制器
app/views/passwords/create.js.rb

<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> 
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
<% if @message == "success" %>
    alert('Success!');
<% else %>
    alert('Something wrong!');
<% end %>

警惕(“成功!”);
警惕(“出了什么事!”);

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

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