What is the best way to get the current controller object's namespace? From inspecting self in a current controller action, I see there is a parameter "REQUEST_URI" that contains a string like "foo_namespace/bar", but I was wondering if there is a better way to get it than to get that (that request_uri wasn't even accessible directly from the controller instance object, I think it was nested in some other params)?
In both the controller and the views, you can parse controller_path, eg.:
namespace = controller_path.split('/').first
I believe you are able to do params[:controller].split("/").first
. This will return that namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With