In my application_helper.rb file I have a function like this:
def find_subdomain
request.domain
end
undefined local variable or method `request'
And I am invoking this method in another helper. How can i get the domain in helper without passing any argument from controller.
I know this is old, but having stumbled across this myself recently I thought I'd chip in. You could add the method to your ApplicationController
and specify it as a helper_method
instead:
class ApplicationController < ActionController::Base
helper_method :find_subdomain
private
def find_subdomain
request.domain
end
end
As others have mentioned, the request object should be passed to your helper, which would let you pass it from the view (ERB) as follows,
<%= find_subdomain(request) %>
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