title: Rails Import Class Method from lib
body: <p>I can't seem to figure out why this will not work.</p>
  
  <p>I have a class in lib with this code:</p>
  
  <pre><code>    class SortMethods
    def initialize(direction, sort)
      @mydirection = direction
      @mysort = sort
    end
    def sort_column(table, field)
      table.column_names.include?(@mysort) ? @mysort : field
    end
  
    def sort_direction
      %w[asc desc].include?(@mydirection) ? @mydirection : "asc"
    end
  end
  </code></pre>
  
  <p>In my trucks_controller I have this code:</p>
  
  <pre><code>    class TrucksController &lt; ApplicationController
    # GET /trucks
    # GET /trucks.json
    require 'sort_methods'
    helper_method :sort_column, :sort_direction
    def index
      search = params[:search]
      msm = SortMethods.new(params[:direction], params[:sort])
      @trucks = Truck.search(search).order(msm.sort_column(Truck, "truck_no") + " " + msm.sort_direction)
  
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @trucks }
      end
    end
  end
  </code></pre>
  
  <p>What I don't understand is what I am doing wrong, I've tried everything that was suggested in this post, another person had the same question yet it does not works.  What am I doing wrong?</p>
  
  <p>post: <a href="https://stackoverflow.com/questions/15110453/rails-how-to-call-methods-from-lib-directory">Rails - how to call methods from lib directory?</a></p>
  
  <p>I should add that i also tried adding .self and it still does not works.</p>