Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require a gem in rails

I'd like to include unitwise in my project, so I added it in the Gemfile and I want to use the core extensions of this gem in a model, so I have to require 'unitwise/ext' which isn't by default. Should I require this file in every models I use it, or is there a way to require it one time for the whole project?

like image 930
Maxence Henneron Avatar asked Mar 01 '26 14:03

Maxence Henneron


2 Answers

You can require it once either by creating an initializer for it, or adding this line to application.rb.

require 'unitwise/ext'
like image 59
usmanali Avatar answered Mar 04 '26 04:03

usmanali


You could create separate ruby file in config/initializer/ to require unitwise/ext which will be available in all place in the project or you could require in application.rb, here also it will be available everywhere in application.

It is better add one line in application.rb, instead creating separate file in initializer to require that file.

like image 22
Vijay Avatar answered Mar 04 '26 04:03

Vijay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!