1
1

More than 3 years have passed since last update.

Railsでlib以下に作った自作クラスを呼び出す

Posted at

config/environment.rbに自作クラスをrequire


lib/
 ├ assets/
 ├ tasks/
 └ test.rb <-追加

test.rb
class Test
    def aa
        puts "aa"
    end
end

config/environment.rbを編集

environment.rb

# Load the Rails application.
require_relative 'application'
require 'test' #これを追記

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

使えるかテスト

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

以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1