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

steve · January 04, 2025 · Last by steve replied at January 10, 2025 · 390 hits
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。

Reply to ken

学到了

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

@kevinyu 用什么 ide?

Reply to steve

应该是 rubymine

Reply to steve

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

Reply to kevinyu

确实比 vs code 强

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