0

Is there any design pattern in Rails by which i can use helper methods in models, without using include ActionView::Helpers?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

0

You can for example call one helper at a time if you want.

ApplicationController.helpers.my_helper_method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.