无法通过浏览器后退按钮离开页面

时间:2014-03-26 20:45:35

标签: ruby-on-rails

当在浏览器中加载这些部分内容时,我无法通过浏览器后退按钮离开页面。页面保持不变,但网址会更改。

导致这种情况的原因是什么?

  match '/signup',  to: 'users#new',            via: 'get'
  match '/signout', to: 'sessions#destroy',     via: 'get'


# /users/new
  def new
    @user = User.new
    render partial: "new", layout: false
  end

# /sessions/new
  def new
    render partial: "new", layout: false
  end

这是我的筹码。这只需点击登录链接一次。

Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as */*
Processing by SessionsController#new as */*
  Rendered sessions/_new.html.erb (0.8ms)
  Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 4ms (Views: 3.3ms | ActiveRecord: 0.0ms)
Completed 200 OK in 4ms (Views: 3.3ms | ActiveRecord: 0.0ms)




Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as HTML
Processing by SessionsController#new as HTML
  Rendered sessions/_new.html.erb (0.8ms)
  Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 3ms (Views: 1.9ms | ActiveRecord: 0.0ms)
Completed 200 OK in 3ms (Views: 1.9ms | ActiveRecord: 0.0ms)




Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as HTML
Processing by SessionsController#new as HTML
  Rendered sessions/_new.html.erb (0.8ms)
  Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms)
Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms)

3 个答案:

答案 0 :(得分:0)

您是否有过滤器重定向公共访问会话#new?您是否定义/签署了路线?

答案 1 :(得分:0)

我可能错了,但正如我在评论中写的那样,我有一个客户在Rails 3.2.12上使用Turbolinks和一组定制的JS库。 Turbolinks引发了许多问题,例如双重提交,其中一个与你提到的类似。我有3个选择:

1-取出Turbolinks(我的临时解决方案,直到我展示团队TL导致它)

2-更改JS lib依赖项

3-将Rails应用程序更新到最新的4.x. (我最后这样做了,这不是太糟糕)

如果我错了,你的案例和设置与我的不相似,那么Github上有一个很好的线程,有些人试图解决它并且似乎仍然是开放的。

https://github.com/rails/turbolinks/issues/256

答案 2 :(得分:0)

检查参数:

Processing SESSION::SESSION#new (for 127.0.0.1 at 2014-04-04 13:50:03) [POST]
Parameters: {"authenticity_token"=>"XXXXX=", "param1"=>"1"}

在您的日志中,如果根据您的列或您想要保留的内容未发送您想要创建的参数,您将看到正在发送的参数。

如果你想创建一个后退按钮,你可以试试这个:

link_to_function "Back", "history.back()"

检查您的行动表格,也许您正在发送其他网址

  <% form_tag :controller=>"sessions",:action=>"new" do %>
    <% @user.each do |user| %>
      <%= user.name %>
      <%= user.lastname %>
    <% end %>
  <% end %>