Reputation: 4677
I have the following in my application_helper.rb file:
module ApplicationHelper
def require_employer_profile_for_employers(page)
if current_user.type == 'Employer'
if current_user.employer_profile
else
flash[:error] = "You must create a profile before accessing #{page}."
redirect_to new_employer_profile_path
end
end
end
end
I try calling it in my projects controller like this:
before_action "require_employer_profile_for_employers('Projects')"
but my server responds with this error:
NoMethodError (undefined method `require_employer_profile_for_employers' for #<ProjectsController:0x007fb741f82e38>):
How do I access the helper in the before_action in the projects controller?
Upvotes: 2
Views: 2011
Reputation: 53038
include ApplicationHelper
in your ProjectsController
:
class ProjectsController < ApplicationController
include ApplicationHelper
# ...
end
Helpers are not directly accessible within a controller as opposed to view layer where they are freely accessible.
Upvotes: 4