Is there any design pattern in Rails by which i can use helper methods in models, without using include ActionView::Helpers?
            Asked
            
        
        
            Active
            
        
            Viewed 152 times
        
    0
            
            
         
    
    
        Zainb Sallahuddin
        
- 25
- 5
2 Answers
0
            
            
        You can for example call one helper at a time if you want.
ApplicationController.helpers.my_helper_method
 
    
    
        Peter Højlund Palluth
        
- 853
- 9
- 26
0
            ActionView::Helpers are intended to be used in your view code. If you have code that you want to use in you model and view, I would recommend creating a helper method in your model.
If you want to create a method that is used in multiple models, I would use concerns. Concerns are used to extract common chunks of code from models to DRY them up. Look here for more info
An alternative to concerns is to create a superclass for common models to inherit from where you can add helper methods
 
    
    
        user2453676
        
- 470
- 9
- 16