Difference between auxiliary files and lib files in rails

What is the difference between helper and lib files in rails? When should these files be used properly?

+6
source share
2 answers

Helpers in Rails are used to organize helpers in 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 contain parts of your code that are not fully related to models, controllers, helpers, or views. Let's say you implement your own web crawler in a separate class. Better save it in lib/my_crawler.rb .

+10
source

helpers are mixins (modules), otherwise you can host classes and whole libraries in / lib

+2
source

Source: https://habr.com/ru/post/901049/


All Articles