Homeland 第一次登陆之后的点赞会跳到首页,flash 登录成功

lihuazhang · August 12, 2017 · Last by jasl replied at August 14, 2017 · 1641 hits

重现步骤:

  1. 退出登录,再次登陆
  2. 随便找一个帖子,点赞
  3. 跳到首页,flash 一个登录成功
  4. 再次点赞,就不会跳到首页,掉赞成功。

@huacnlee @jasl

https://github.com/ruby-china/homeland/blob/master/app/assets/javascripts/app.coffee#L117 这个判断造成的跳转,结合 https://github.com/ruby-china/homeland/blob/master/app/assets/javascripts/app.coffee#L325 这里 还有 https://github.com/ruby-china/homeland/blob/master/app/views/layouts/application.html.erb#L83 这里,应该是 turbolinks 的锅,登录成功要么补上这个赋值要么干脆刷新全站好了

笔记本上没 homeland 的开发环境。。。

Reply to jasl

又甩锅给 Turbolinks。

把 user_id 存到 meta 里:

<% if current_user %>
  <meta name="current-user-id" content="<%= @current_user.id %>">
<% end %>
isLogined : ->
  document.getElementsByName('current-user-id').length > 0

这样就不用老是关心变量了。

然后你会发现 Ruby China 已经加有 current-user 这个 meta。

Reply to Rei

登录后 App.current_user_id = 1107; 渲染到了 HTML 上,但是 App.current_user_id => null App.isLogined() => false 就是说那 JS 没按预期方式执行,那我说更正下说法“没有正确的使用 Turbolinks”可以了吧...

当然你说的改法是很好的,我没注意到有这个 meta

Reply to jasl

没有修复

isLogined : ->
  document.getElementsByName('current-user-id').length > 0

应该改成:

isLogined : ->
  document.getElementsByName('current-user').length > 0

@lihuazhang 新服务器没添加我公钥,联系其他管理员部署了,估计要过会

Reply to jasl

你都没试过,我加了你的

但是你也不能部署,还得走 Docker 打包发布的流程

Reply to huacnlee

我最后还是没弄

You need to Sign in before reply, if you don't have an account, please Sign up first.