如何获取Rails中所有模型、控制器、操作和方法名称

发布于 2024-09-12 15:04:29 字数 148 浏览 4 评论 0原文

在运行时,我们可以通过controller_name和action_name方法获取当前控制器和当前动作名称,

如果可能的话,我也想获取所有剩余的控制器和动作名称和模型。

任何可用于获取所有控制器名称和动作的rails方法应用程序控制器中的操作名称。

In runtime we can get the current controller and current action names by controller_name and action_name methods like wise,

I want to get all the remaining controllers and action names and models too if possible..

Any rails method available to get all the controller names and the action names in application controller.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言月老 2024-09-19 15:04:29
@table_names =  ActiveRecord::Base.connection.tables
    @model_names = Array.new
    @model_names.each do |table_to_model|
      @model_names = @model_names.insert(@model_names.length,table_to_model.camelize.singularize) unless table_to_model.blank?
    end

这是获取所有型号名称的方式

@table_names =  ActiveRecord::Base.connection.tables
    @model_names = Array.new
    @model_names.each do |table_to_model|
      @model_names = @model_names.insert(@model_names.length,table_to_model.camelize.singularize) unless table_to_model.blank?
    end

This is how you get all Model name

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文