Closed ciaoben closed 9 years ago
In your application.rb file extend your autoload paths like below;
config.autoload_paths << Rails.root.join('app', 'errors')
And please use stackoverflow or similar platforms for asking 'how to questions'.
Why it has been closed?
The solution provided doesn't work!
And this is not an "how to". Rails doesn't load automatically all the new folders in app??? Why this isn't the case-
@ciaoben Also you can use spring stop
then rails s
to refresh your application. By this way you don't need to explicitly extend autoload_paths.
Try this and tell me the result please.
@meinac yes, it seems to work. Thanks. I am using the console, so I've done spring stop
and rails c
and everything worked fine, without
config.autoload_paths << Rails.root.join('app', 'errors')
Can you give me a brief explanation?
spring eagerload you application and keep it running. When you add a new folder to app, rails automatically add it to autoload paths but since you spring process already started it doesn't know that a new folder was added, so you have to restart the spring process to get the new path on the autoload paths
Thanks, it is all clear now!
I am trying to create custom exceptions in rails, but I 've problem with my designed solution.
Here what I've done so far:
-Create in the
app/
folder a folder namederrors/
with a fileexceptions.rb
in it.app/errors/exceptions.rb
:raise Exceptions::AppError.new("User is not authorized")
But when I call the controller's action, here is what I get:
I think I don't have fully understood how to create new directories and files, and use them.
I've read that everything created in the
app
dir, is eager loaded, so I can't understand where is the problem.