简体   繁体   English

Rails - 即使在我的服务器中显示“重定向到 http://localhost:3000”,也不会重定向

[英]Rails - Not Redirecting even though it says “Redirected to http://localhost:3000” in my sever

I have a form_with that works in my server but not in my brother:我有一个 form_with 可以在我的服务器上运行但在我的兄弟中不起作用:

My form in my view :我认为我的形式:

<%= form_with url: sessions_path, method: "post" do |f|%> 
          <h3 class="text-center text-info">Se Connecter</h3>
          <div class="form-group">
              <%= label_tag "email", "Adresse mail:", class: "text-info" %><br>
              <%= f.email_field "email", class: "form-control" %>
          </div>
          <div class="form-group">
              <%= label_tag "password", "Mot De Passe", class: "text-info" %><br>
              <%= f.password_field "password", class: "form-control" %>
          </div>
          <div class="form-group" style="padding: 20px;">
            <%= f.submit "Se connecter", class: "btn btn-info btn-md" %>
          </div>
      <% end %>

My controller :我的控制器:

def create
  user = User.find_by(email: params[:email])

  if user && user.authenticate(params[:password])
    session[:user_id] = user.id
    redirect_to gossips_path, :notice => "Bienvenue <%= User.find_by(id: session[:user_id]).first_name %>"
  else
    flash.now[:danger] = 'Email ou Mot De Passe invalide'
    render 'new'
  end
end

My server :我的服务器:

Started POST "/sessions" for ::1 at 2020-10-04 13:10:25 +0200
Processing by SessionsController#create as JS
  Parameters: {...}
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "..."], ["LIMIT", 1]]
  ↳ app/controllers/sessions_controller.rb:8
#<User:0x00007f667d7f36f0>
Redirected to http://localhost:3000/gossips
Completed 302 Found in 246ms (ActiveRecord: 0.2ms)


Started GET "/gossips" for ::1 at 2020-10-04 13:10:26 +0200
Processing by GossipsController#index as JS
  Rendering gossips/index.html.erb within layouts/application
  Gossip Load (0.4ms)  SELECT "gossips".* FROM "gossips"
  ↳...
  Rendered gossips/index.html.erb within layouts/application (75.5ms)
Completed 200 OK in 102ms (Views: 85.6ms | ActiveRecord: 12.8ms)

But my browser stay in the same page.但我的浏览器停留在同一页面。 I don't know why.我不知道为什么。 Can you help me?你能帮助我吗?

<%= form_with url: sessions_path, method: "post", local: true do |f|%>
  # ...
<% end %>

form_with unlike form_for defaults to remote: true . form_withform_for不同,默认为remote: true That means that the form will by default send an AJAX request and thus the redirect does nothing in the browser.这意味着表单将默认发送 AJAX 请求,因此重定向在浏览器中不执行任何操作。 You can see that its an AJAX request by:您可以通过以下方式看到它的 AJAX 请求:

Processing by SessionsController#create as JS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重定向到http:// localhost:3000 / session / new - Redirected to http://localhost:3000/session/new Ruby on Rails Devise Always localhost:3000将被重定向 - Ruby on Rails Devise Always localhost: 3000 will be redirected 无法使用Rails ping http:// localhost:3000 - cannot ping http://localhost:3000 with Rails Ruby on Rails:http:// localhost:3000无法正常工作 - Ruby on Rails: http://localhost:3000 not working 如何获取我的Rails应用程序的基本URL(例如http:// localhost:3000)? - How do I get the base URL (e.g. http://localhost:3000) of my Rails app? Ember CLI 和 Rails:代理到 http://localhost:3000 时出错 - Ember CLI and Rails: Error proxying to http://localhost:3000 为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000? - Why does Ruby on Rails use http://0.0.0.0:3000 instead of http://localhost:3000? Rails 5:通过与http:// localhost:3000的不安全连接阻止了对地理定位的访问 - Rails 5: Access to geolocation was blocked over insecure connection to http://localhost:3000 Cloud 9正在运行Rails服务器,但未连接到http:// localhost:3000 - Cloud 9 running rails server, but not connected to http://localhost:3000 Ruby on Rails无法访问MAC上的http:/ localhost:3000 - Ruby on rails cannot access http:/localhost:3000 on MAC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM