title: Ordering Data by datetime Entry in Rails
body: <p>I have content_date row in my table that uses the datetime field type. I would like to order my data (content_items) using this field.</p>
  
  <p><strong>models/content_item.rb</strong>  </p>
  
  <pre><code>class ContentItem &lt; ActiveRecord::Base
    belongs_to :calendar
  end
  </code></pre>
  
  <p><strong>models/calendar.rb</strong>  </p>
  
  <pre><code>class Calendar &lt; ActiveRecord::Base
      has_many :content_items
  end
  </code></pre>
  
  <p><strong>controllers/content_items_controller.rb</strong>  </p>
  
  <pre><code>  def index
      @calendar = Calendar.find(params[:calendar_id])
    end
  </code></pre>
  
  <p>I tried this, but had no success:</p>
  
  <p><strong>controllers/content_items_controller.rb</strong>  </p>
  
  <pre><code>  def index
      @calendar = Calendar.find(params[:calendar_id])
      @content_item = @calendar.content_items.order(content_date: :desc)
    end
  </code></pre>
  
  <p>Github Link: <a href="https://github.com/JeremyEnglert/baked" rel="nofollow">https://github.com/JeremyEnglert/baked</a></p>