I have a module ApplicationHelper in app/helpers/application_helper.rb defined like this
module ApplicationHelper
def some_method(arg)
end
end
and i have my view file is here
app/views/v1/admin/messages/show.json.jbuilder
So i am trying to access the
some_method()
in view file but it doesn't reflect! Is this due to namespacing? or what i am not able to understand. It would be Great if someone explains the concept. Thanks in advance!
it says undefined method error what could be the reason?
You didn't include your controller code, but we'll assume it ultimately inherits from
ActionController::API(as it should it if it is an API controller). If so, that is the root of it rather than namespacing, etc. Per the ActionController documentation:One of the side effects of the thinner API controller is that they don't automatically include helpers like a standard Rails controller. You can easily add that back in, though.
messages_controller.rb
app/helpers/application_helper.rb
app/views/messages/show.json.jbuilder
If you have lots of API controllers, you can of course stick it in a base controller class they all inherit from like so: