Ruby on rails 如何在rails控制台中将控制器打印为文本?

Ruby on rails 如何在rails控制台中将控制器打印为文本?,ruby-on-rails,devise,rails-console,Ruby On Rails,Devise,Rails Console,我想查看design::RegistrationController(出于好奇,我将从中继承,如图所示) 我尝试了明显的rails c,然后put designe::registrations controller和一些变体(例如.to_s),但没有成功 它是否可以在某个地方查看,我是否可以将其打印到rails控制台以查看它?这是IRB内置源代码浏览的替代控制台 安装并用导轨c启动控制台,控制台将启动撬杆而不是IRB 然后,您可以使用show source从控制台右侧查看gem的源代码: max

我想查看
design::RegistrationController
(出于好奇,我将从中继承,如图所示)

我尝试了明显的
rails c
,然后
put designe::registrations controller
和一些变体(例如
.to_s
),但没有成功

它是否可以在某个地方查看,我是否可以将其打印到rails控制台以查看它?

这是IRB内置源代码浏览的替代控制台

安装并用导轨c启动控制台,控制台将启动撬杆而不是IRB

然后,您可以使用
show source
从控制台右侧查看gem的源代码:

max@pop-os ~/p/sandbox> rails c
Running via Spring preloader in process 29286
Loading development environment (Rails 6.0.2.1)
[1] pry(main)> show-source Devise::RegistrationsController

From: /home/linuxbrew/.linuxbrew/lib/ruby/gems/2.7.0/gems/devise-4.7.2/app/controllers/devise/registrations_controller.rb @ line 3:
Class name: Devise::RegistrationsController
Number of monkeypatches: 4. Use the `-a` option to display all available monkeypatches
Number of lines: 166

class Devise::RegistrationsController < DeviseController
  prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
  prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
  prepend_before_action :set_minimum_password_length, only: [:new, :edit]

  # GET /resource/sign_up
  def new
    build_resource
    yield resource if block_given?
    respond_with resource
  end

  # POST /resource
  def create
    build_resource(sign_up_params)

    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end
  end
:
max@pop-os~/p/sandbox>rails c
通过过程29286中的弹簧预紧器运行
加载开发环境(Rails 6.0.2.1)
[1] pry(主)>显示源设备::注册控制器
From:/home/linuxbrew/.linuxbrew/lib/ruby/gems/2.7.0/gems/designe-4.7.2/app/controllers/designe/registrations\u controller.rb@第3行:
类名:designe::RegistrationController
monkeypatches的数量:4。使用“-a”选项显示所有可用的monkeypatches
行数:166
类designe::RegistrationController
如果你不想依赖IRB,你可以使用和IO.readlines。但依我看,这似乎是浪费时间,它是IRB内置源代码浏览的替代控制台

安装并用导轨c启动控制台,控制台将启动撬杆而不是IRB

然后,您可以使用
show source
从控制台右侧查看gem的源代码:

max@pop-os ~/p/sandbox> rails c
Running via Spring preloader in process 29286
Loading development environment (Rails 6.0.2.1)
[1] pry(main)> show-source Devise::RegistrationsController

From: /home/linuxbrew/.linuxbrew/lib/ruby/gems/2.7.0/gems/devise-4.7.2/app/controllers/devise/registrations_controller.rb @ line 3:
Class name: Devise::RegistrationsController
Number of monkeypatches: 4. Use the `-a` option to display all available monkeypatches
Number of lines: 166

class Devise::RegistrationsController < DeviseController
  prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
  prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
  prepend_before_action :set_minimum_password_length, only: [:new, :edit]

  # GET /resource/sign_up
  def new
    build_resource
    yield resource if block_given?
    respond_with resource
  end

  # POST /resource
  def create
    build_resource(sign_up_params)

    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end
  end
:
max@pop-os~/p/sandbox>rails c
通过过程29286中的弹簧预紧器运行
加载开发环境(Rails 6.0.2.1)
[1] pry(主)>显示源设备::注册控制器
From:/home/linuxbrew/.linuxbrew/lib/ruby/gems/2.7.0/gems/designe-4.7.2/app/controllers/designe/registrations\u controller.rb@第3行:
类名:designe::RegistrationController
monkeypatches的数量:4。使用“-a”选项显示所有可用的monkeypatches
行数:166
类designe::RegistrationController

如果你不想依赖IRB,你可以使用和IO.readlines。但我认为这似乎是浪费时间

它是开源的--请正确查看代码…您可以在
design
gem存储库中查看它。e、 g.@dbugger随机问题。代码是否可以在rails应用程序中进行搜索(并可编辑),或者是在github上查看它的唯一地方?据我所知不是这样。如果可以的话,我也不认为你会想编辑它,它是非常可定制的,ruby可以让你修补不容易定制的东西。看看Desive repo,它用于定制控制器、视图等。我们有大约五种Desive变体,都是通过定制不同的位来完成的。您也可以使用
bundle open designe
在编辑器中打开它,它是开源的——看看代码……您可以在
Desive
gem存储库中查看它。e、 g.@dbugger随机问题。代码是否可以在rails应用程序中进行搜索(并可编辑),或者是在github上查看它的唯一地方?据我所知不是这样。如果可以的话,我也不认为你会想编辑它,它是非常可定制的,ruby可以让你修补不容易定制的东西。看看Desive repo,它用于定制控制器、视图等。我们有大约五种Desive变体,所有这些都是通过定制不同的位来完成的。您也可以使用
bundle open designe