gpt4 book ai didi

ruby-on-rails - 不同的前缀 : "/" and "http:/localhost:3000" with devise

转载 作者:太空宇宙 更新时间:2023-11-03 16:41:49 24 4
gpt4 key购买 nike

我正在使用带有 rails 5.1.4 的设计。当我尝试使用错误的密码登录时,出现此错误:

different prefix: "/" and "http:/localhost:3000"

我将 rbenv 与 ruby​​ 2.4.1 结合使用。我在使用 ruby​​ 2.3.3 时遇到了同样的问题。

这是完整的堆栈跟踪:

    /home/badr/.rbenv/versions/2.4.1/lib/ruby/2.4.0/pathname.rb:520:in `relative_path_from'
devise (4.3.0) lib/devise/failure_app.rb:58:in `recall'
devise (4.3.0) lib/devise/failure_app.rb:39:in `respond'
actionpack (5.1.4) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.4) lib/abstract_controller/base.rb:124:in `process'
actionpack (5.1.4) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.4) lib/action_controller/metal.rb:242:in `block in action'
devise (4.3.0) lib/devise/failure_app.rb:21:in `call'
devise (4.3.0) lib/devise/delegator.rb:5:in `call'
warden (1.2.7) lib/warden/manager.rb:143:in `call_failure_app'
warden (1.2.7) lib/warden/manager.rb:129:in `process_unauthenticated'
warden (1.2.7) lib/warden/manager.rb:44:in `call'
rack (2.0.3) lib/rack/etag.rb:25:in `call'
rack (2.0.3) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.3) lib/rack/head.rb:12:in `call'
rack (2.0.3) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.3) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.4) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.4) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.4) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.4) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.4) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.3) lib/rack/method_override.rb:22:in `call'
rack (2.0.3) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.3) lib/rack/sendfile.rb:111:in `call'
railties (5.1.4) lib/rails/engine.rb:522:in `call'
puma (3.10.0) lib/puma/configuration.rb:225:in `call'
puma (3.10.0) lib/puma/server.rb:605:in `handle_request'
puma (3.10.0) lib/puma/server.rb:437:in `process_client'
puma (3.10.0) lib/puma/server.rb:301:in `block in run'
puma (3.10.0) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

知道这可能来自哪里吗?

更新:我在 cloud9 上创建了一个工作区,以查看该项目在另一台机器上是否运行良好,确实如此!所以我的 ruby​​ 安装似乎有问题。在问题开始发生之前,我已经破坏了我的 linux 机器上的项目文件夹,并从 bitbucket 中再次克隆了它。

最佳答案

这是您的操作的设计工作流程。

您填写了表格 session/new.html.erb .设计使用 form_for将表单绑定(bind)到对象并使用 routes.rb 文件中的 RESTful 路由。

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>

这个form_for标签会生成下面的html表单,resource会被替换为一个基于UserAdmin的对象 由您的模型 SessionsController#new action使用代码 self.resource = resource_class.new(sign_in_params)

<form accept-charset="UTF-8" action="/users" method="post" class="nifty_form">

当您单击提交 按钮时,html 表单将触发对url /usersPOST 请求。

POST 请求将从您的服务器路由器接收,它根据您在routes.rb 上配置的设置决定如何回应

如果您的routes.rb 文件配置为符合设计 指南,这将是您的routes.rb 文件

devise_for :users

生成以下路由

user_session POST   /users/sign_in                    {controller:"devise/sessions", action:"create"}

所以当从服务器接收到请求时,它应该从sessions_controller.rb#create action处理。 .您可以在 Github 上或安装在 RVM 或 RBENV 文件夹中的 GEMS 中显示此 Controller 。您还可以通过设置 binding.pry

来调试它们
  # POST /resource/sign_in
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message!(:notice, :signed_in)
sign_in(resource_name, resource)
yield resource if block_given?
respond_with resource, location: after_sign_in_path_for(resource)
end

当您决定使用错误的身份验证时,您正在调用此 method

def authenticate!
resource = password.present? && mapping.to.find_for_database_authentication(authentication_hash)
hashed = false

if validate(resource){ hashed = true; resource.valid_password?(password) }
remember_me(resource)
resource.after_database_authentication
success!(resource)
end

mapping.to.new.password = password if !hashed && Devise.paranoid
fail(:not_found_in_database) unless resource
end

因此,当您提供无效的密码和电子邮件时,validate(resource){ hashed = true; resource.valid_password?(password) 将返回 false 并执行这段代码

mapping.to.new.password = password if !hashed && Devise.paranoid
fail(:not_found_in_database) unless resource

由于某些原因会重定向到错误的 url。

我相信这段代码是为了在您的页面中显示错误, View session/new.html.erb。所以我相信在 Devise 标准 Controller 中没有 GET 请求,只是重新渲染带有错误消息的 View 。

所以我的问题是,您是否覆盖了 Devise Controller 以赋予它这种行为?您能否与我们分享您的 routes.rb 文件和 rake routes 的输出?

关于ruby-on-rails - 不同的前缀 : "/" and "http:/localhost:3000" with devise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47206273/

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