为什么在传递URL时将其重定向到localhost:// 3000?

时间:2019-08-21 06:55:38

标签: ruby-on-rails

”“我创建了一个使用devise gem提供登录和注册页面的网站。我正在尝试到达localhost:3000/users/sign_in这条路径。但是它正在重定向到localhost://3000

“这是针对ruby 2.5和rails 6.0的。我尝试了一些可能的方法,例如清除cookie,重新启动服务器。但是我仍然面临着同样的问题。”


<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>

   #fields for sign_up page

<% end %>

<%= render "devise/shared/links" %>

“我希望获得登录页面,但它会重定向到根URL”

日志

Started GET "/users/sign_in" for 127.0.0.1 at 2019-08-21 13:22:56 +0530
   (0.3ms)  SET NAMES utf8mb4,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
   (0.3ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
Processing by Devise::SessionsController#new as HTML
  User Load (0.3ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 16ms (ActiveRecord: 1.6ms | Allocations: 9317)


Started GET "/" for 127.0.0.1 at 2019-08-21 13:22:56 +0530
Processing by Rails::WelcomeController#index as HTML
  Rendering /home/parvathy/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0/lib/rails/templates/rails/welcome/index.html.erb
  Rendered /home/parvathy/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0/lib/rails/templates/rails/welcome/index.html.erb (Duration: 7.0ms | Allocations: 315)
Completed 200 OK in 18ms (Views: 13.3ms | ActiveRecord: 0.0ms | Allocations: 1772)

1 个答案:

答案 0 :(得分:-1)

这归结为格式错误的URL。

  
    

localhost:// 3000

  

格式不正确。

  
    

localhost:3000 / blah

  

在端口3000上表示本地主机

冒号必须放在端口号之前。

协议装饰器://用于http:// https:// ftp://等

http是协议,http的默认端口为80,https的默认端口为443,但可以像我们在此处指定的那样将其放在顶级域之后。

  

http://localhost:3000

应该解决您的问题。