Access Request Object in Rail Assistant

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 call this method in another helper. How can I get the domain in the helper without passing any arguments from the controller.

+8
ruby ruby-on-rails
source share
2 answers

As already mentioned, the request object must be passed to your assistant, which will allow you to pass it from the view (ERB) as follows:

 <%= find_subdomain(request) %> 
+2
source share

I know this is old, but having stumbled upon it, I recently thought I'd write it down. You can add this method to your ApplicationController and specify helper_method :

 class ApplicationController < ActionController::Base helper_method :find_subdomain private def find_subdomain request.domain end end 
+1
source share

All Articles