Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest looking into doing something like the following:</p> <p><strong>Pins.rb</strong>: </p> <p>This will result in having the featured at the top of the list, with a secondary sort of them sorted by when they were created. <em>(Note two methods of sorting by boolean)</em></p> <pre><code>class Pin &lt; ActiveRecord::Base belongs_to :user default_scope order: 'created_at DESC' # Method 1 scope :featy, order('featured DESC, created_at DESC') # Method 2 # scope :featy, order('(case when featured then 1 else 0 end) DESC, created_at DESC') end </code></pre> <p><strong>User.rb</strong>:</p> <pre><code>class User &lt; ActiveRecord::Base has_many :pins end </code></pre> <p><strong>UsersController.rb</strong>:</p> <pre><code>class UsersController &lt; ApplicationController def show @user = User.find(params[:id]) # Pins are accessed via: @user.pins # These should be sorted by `created_at DESC` as that is the default_scope end end </code></pre> <p><strong>users/show.html.erb</strong>: <em>This is all of the users pins sorted by <code>created_at desc</code></em></p> <pre><code>&lt;%= @user.pins %&gt; </code></pre> <p><strong>PinsController.rb</strong>:</p> <pre><code>class UsersController &lt; ApplicationController def index # Pins sorted by created_at: @pins = Pin.all # Pins sorted by created_at with all featured on top: @pins = Pin.featy end end </code></pre> <p><strong>pins/index.html.erb:</strong> <em>This is all pins sorted by <code>created_at desc</code> with all featured on top</em></p> <pre><code>&lt;%= @pins %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload