Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between helper files and lib files in rails

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

like image 580
Rahul Avatar asked Nov 08 '11 16:11

Rahul


1 Answers

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.

like image 112
bor1s Avatar answered Sep 28 '22 18:09

bor1s