0

I simply want to create a custom exception that I can use as part of a fail from either a model or a controller. Is the lib directory the correct place for this, or are helpers / concerns useful for this.

If it is the lib directory what do I need to import and where?

1 Answer 1

1

You should add the exception class to your app/models folder. Anything that's business logic for your application should be in the app/models folder (as this article talks about in more detail). The lib folder is where you put code that is basically external to your app (almost like the last step before you extract it into a gem some day).

Here is an example exception that you can refer to from anywhere in your app:

# app/models/my_exception.rb
class MyException < RuntimeError
end

And since the app/models folder is already autoloaded you're all set -- no need to require the file in an initializer or anything like that.

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

3 Comments

Thanks, will try that out when I get the chance!
Hey this isn't working for me... I'll change the question above to reflect that
@Imran I see you accepted it, did it start working now?

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.