【问题标题】:How to access current_user in stimulus_reflex如何在刺激反射中访问 c​​urrent_user
【发布时间】:2021-01-24 12:17:18
【问题描述】:

在这个反射中,我想将 lastupdateby 字段设置为 current_user。我无法让它工作。我需要做些什么来获得反射的价值吗?关于我做错了什么有什么想法吗?如果我硬编码该值而不是 current_user 它可以工作。我一定是引用错了。

def toggle
 todo = Todo.find(element.dataset[:id])
 todo.update(completed_at: (todo.completed_at? ? nil : Time.current), lastUpdatedBy: current_user)
end

【问题讨论】:

  • Ref :- headway.io/blog/a-future-for-rails-stimulusreflex,你要加delegate :current_user, to: :connection
  • 就是这样。谢谢!搞定了。
  • @Salil 为什么不将此添加为答案,以便人们可以投票并且 OP 可以接受它。这样其他用户会更容易看到它:-)
  • @RolandStuder:当然,完成。

标签: ruby-on-rails stimulusjs stimulus-reflex


【解决方案1】:

参考this,

在你的反射类中添加以下行。

delegate :current_user, to: :connection

【讨论】:

    猜你喜欢
    • 2021-03-06
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多