Reputation: 278
class ApplicationController < ActionController::Base
class InvalidParam < StandardError;end
end
What is the reason for including another class inside application controller?? What will be the behavior for other controllers?
Upvotes: 0
Views: 112
Reputation: 26363
There's no structural difference between InvalidParam and StandardError - I'm betting that the developer is layering his/her own semantics on InvalidParam. That's naughty because it will just confuse the reader.
The code declares a nested class called InvalidParam for the purposes of Exception handling. The developer wants to be able to raise and rescue exceptions with InvalidParam rather than StandardError - most likely because they want to distinguish between system exceptions and their own.
Upvotes: 1
Reputation: 23770
The reason for including another class inside application controller is that the class will be visible only inside the controller (scoping). Other controllers will not be influenced.
Upvotes: 0
Reputation: 4489
Can it be declaration of nested class that will not be used anywhere else?
Upvotes: 0