What exactly is the difference between helper
files and lib
files in rails? When should these files be used appropriately?
Helpers in Rails are used to organize helpers in the views. So you can create a method in some helper module, say:
module SomeModule
def markdown(string)
#some behaviuor
end
end
and then use it in the view: markdown("Hello world")
.
The Lib folder should keep the parts of your code that are not completely relevant to models, controller, helpers or views. Say you implement your own web crawler in separate class. It is better to keep it in lib/my_crawler.rb
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With