title: Bad value for range when using a controller helper method
body: <p>I'm trying to run a helper method through my ActionController as seen below.</p>
  
  <pre><code># app/controllers/application_controller.rb
  
  class ApplicationController &lt; ActionController::Base
    def set_count(object_count, class_name)
      ["new", "create"].include? action_name ? object_count = class_name.count + 1 : object_count = class_name.count
      end
  end
  </code></pre>
  
  <p>When I request the new action of that controller I get the error "bad value for range".</p>
  
  <pre><code># app/views/subjects/new.html.erb
  
  &lt;%= form_for @subject do |f| %&gt;
    &lt;table summary="Subject form field"&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;%= f.label :position %&gt;&lt;/th&gt;
          &lt;td&gt;&lt;%= f.select :position, 1..@subject_count %&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Keep in mind this method works if I place it in the controller itself:</p>
  
  <pre><code># app/controllers/subjects.rb
  
  def set_count
    ["new", "create"].include? action_name ? @subject_count = Subject.count + 1 : @subject_count = Subject.count
  end
  </code></pre>
  
  <p>and run it as follows:</p>
  
  <p><code>before_action :set_count, only: [:new, :create, :edit, :update]</code></p>
  
  <p>I'd much rather have it as a helper because a couple other controllers use something similar to this. I tried converting the range to a Fixnum using <code>to_i</code> but all I get is a select box with no numbers.</p>