Ruby homeland 源码中 list_actions.rb 中的 current_user 在哪里定义的?

steve · 2025年01月04日 · 最后由 steve 回复于 2025年01月10日 · 359 次阅读
if current_user
        scope = scope.without_nodes(current_user.block_node_ids) if without_nodes
        scope = scope.without_users(current_user.block_user_ids)
end

用 def current_user 在代码里能搜到 3 个,但看起来都不像上面那个 current_user 的定义。

@ken ListActions 没有继承或 include 相关的 class 或 module,用 vs code 的 ruby lsp 扩展也找不到 current_user 的定义

帮你问了,应该就是 devise 里定义的

(byebug) method(:current_user).source_location
["/path_to/homeland/app/controllers/application_controller/deviseable.rb", 34]

@ken @greatghoul 多谢。topics_controller.rb 里也有 current_user,是 include Deviseable 获取的方法。 但 list_actions.rb 没看到继承和 include current_user 方法。

list_actions.rb 是个 module,被 include 到 topic_controller.rb 里面调用,调用环境是 topic_contorller。

ken 回复

学到了

@Rei 这么解释可以理解。不过 vs code 里不能跳转到方法定义处,ruby lsp 不能理解这个代码关系。这样写未必是好的方式。

@kevinyu 用什么 ide?

steve 回复

应该是 rubymine

steve 回复

rubymine 用了很多年了感觉很好用啊

kevinyu 回复

确实比 vs code 强

需要 登录 后方可回复, 如果你还没有账号请 注册新账号