9

I have a ColumnSort module in my rails project.

module ColumnSort
  extend ActiveSupport::Concern

  def sort_column
    # do something
  end
end

And I'm using it from CompaniesController and UsersController.

class CompaniesController < ApplicationController
  include ColumnSort
  helper_method :sort_column
end

class UsersController < ApplicationController
  include ColumnSort
  helper_method :sort_column
end

It works fine. But I want to write the line helper_method :sort_column in the module ColumnSort. How can I write it?

ironsand
  • 14,329
  • 17
  • 83
  • 176

1 Answers1

-3

You don't have to call the helper_method. helper_method is to expose a controller method to the view not to import methods from a helper class.

include ColumnSort

This line, includes already all methods contained within the Helper Class.

You can read more about it in the Rails API docs: http://apidock.com/rails/ActionController/Helpers/ClassMethods/helper_method

Alexander Luna
  • 5,261
  • 4
  • 30
  • 36