Call your own class created under lib with Rails

Requires your own class in config / environment.rb


lib/  ├ assets/  ├ tasks/ └ test.rb <-Add

test.rb


class Test
    def aa
        puts "aa"
    end
end

Edit config / environment.rb

environment.rb



# Load the Rails application.
require_relative 'application'
require 'test' #Add this

# Initialize the Rails application.
Rails.application.initialize!

Test if it can be used

 % rails c
Running via Spring preloader in process 62643
Loading development environment (Rails 6.0.3.2)
[1] pry(main)> Test
=> Test

that's all

Recommended Posts

Call your own class created under lib with Rails
Use your own classes in the lib directory with Rails6
[Java] Sort ArrayList with elements of your own class
Call your own method with PreAuthorize in Spring Security
Make your own Rails validate
Make your own sampler with JMeter
Redirect to your own domain with rack-rewrite on Heroku x Rails
Create your own validator with Bean Validation
Downgrade an existing app created with rails 5.2.4 to 5.1.6
[Rails] Organize your code neatly with gem active_decorator
Java method call from RPG (method call in own class)
rails new app is not created with app name
Add your own authentication items with Spring Security
Create your own Utility with Thymeleaf with Spring Boot
Rails development environment created with VSCode and devcontainer