I created a API-Only Rails Application but I need a administrative area to manage data. So I created this controller:
require 'rails/application_controller'
require_relative '../helpers/admin_helper'
class AdminController < Rails::ApplicationController
include AdminHelper
def index
@q = Promotion.search(params[:q])
@promotions = @q.result(distinct: true).page(params[:page]).per(30)
render file: Rails.root.join('app', 'views', 'admin', 'index.html')
end
end
Bot I can't access Helper, even requiring the module. Look a Helper:
module AdminHelper
def teste
'ok'
end
end
And the error generated:
ActionController::RoutingError (uninitialized constant AdminController::AdminHelper):
If you are using ActionController::API (and you should when implementing APIs), you can make use of application helpers by including the dedicated mixin :
class Api::V1::ApiController < ActionController::API
include ActionController::Helpers
helper MyHelper
end
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