Refactor the code

How can i refactor the below code

class BlogPostsController < ApplicationController
  def ex
    @p_p = B.where(‘published_at <= ?’,
    @unp_p = BlogPost.where(‘published_at = ? OR published_at > ?’, nil,

How would I optimize the following code?


How can i refactor the below code

These smell like homework problems. Asking us to do your homework for
you will do Bad Things to your grades if your teacher finds out, your
professional reputation later, and of course your understanding of
what should actually be done. If you need help understanding the
concepts involved, you need to make that clear, so we can steer you
towards actual enlightenment rather than a plagiarized solution.