title: Rails helper method with external classes
body: <p>I am going to try and explain this the best way I can...so here we go...</p>
  
  <p>Here is my old(working) controller for truck.  What it does is it sorts by columns and asc/desc orders which works as intended.</p>
  
  <pre><code>class TrucksController &lt; ApplicationController
    # GET /trucks
    # GET /trucks.json
    require 'sort_methods'
    helper_method :sort_column, :sort_direction
    def index
      @trucks = Truck.search(params[:search]).order(SortMethods.sort_column(Truck, "truck_no", params[:sort]) + " " + SortMethods.sort_direction(params[:direction]))
  
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @trucks }
      end
    end
  
  private
  
    def sort_column
      Truck.column_names.include?(params[:sort]) ? params[:sort] : "truck_no"
    end
  
    def sort_direction
      %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
    end
  end
  </code></pre>
  
  <p>From what I understand the helper_method here is called so that when page is passed with no arguments, it has a default it can revert to and sort methods below are the methods that cause the default behavior.  All this works as intended, I can load pages and sort.</p>
  
  <p>Now the @ trucks is calling a class in lib which has identical methods to my sort_methods because I call those methods multiple times and i'm trying to DRY code this.  This works, still because I've done the class in this way:</p>
  
  <pre><code>class SortMethods
    def self.sort_column(table, field, sort)
      table.column_names.include?(sort) ? sort : field
    end
  
    def self.sort_direction(direction)
      %w[asc desc].include?(direction) ? direction : "asc"
    end
  end
  </code></pre>
  
  <p>Alright so code like this works as intended, the problem is that I am repeating sort methods twice, in my controller and in the SortMethods class.  What I would like to do is set the default for the helper class using the SortMethods but if I try to call it using this code:</p>
  
  <pre><code>helper_method :SortMethods.sort_column(Truck, "truck_no", params[:sort]), SortMethods.sort_direction(params[:direction])
  </code></pre>
  
  <p>I receive following message:</p>
  
  <pre><code>undefined local variable or method `sort_column' for #&lt;#&lt;Class:0x1a3a780&gt;:0x1852f08&gt;
  </code></pre>
  
  <p>My assumption is one of the variables I am passing in is nil, I can't figure out which one and how would I go about it to avoid this problem?  Is there another way I can default to this if no parameters are set in place.  I also tried moving helper in index but that gives me this error:</p>
  
  <pre><code>undefined method `sort_column' for :SortMethods:Symbol
  </code></pre>