Skip to content

Instantly share code, notes, and snippets.

@Hates
Created November 3, 2011 17:55
Show Gist options
  • Save Hates/1337198 to your computer and use it in GitHub Desktop.
Save Hates/1337198 to your computer and use it in GitHub Desktop.
def index
@articles = Article.admin
@for = params[:for]
if @for.nil? || @for == "all"
@for = "all"
else
for_method = "for_#{@for}"
@articles = @articles.send(for_method.to_sym)
end
@order = params[:order]
@articles = @articles.ordered_by_urgent
if @order == "views"
@articles = @articles.ordered_by_views_count
elsif @order == "dated"
@articles = @articles.ordered_by_created_at
elsif @order == "datea"
@articles = @articles.ordered_by_created_at_asc
elsif @order == "placement"
@articles = @articles.ordered_by_placement
elsif @order == "category"
@articles = @articles.ordered_by_category
else
@articles = @articles.ordered_by_title
end
@articles = @articles.ordered_by_id
@articles = @articles.paginate :page => params[:page], :per_page => 50
end
scope :ordered_by_title,
order("LOWER(title) ASC")
scope :ordered_by_views_count,
order("views_count DESC")
def self.for_tomorrow
placement_day(1.day.from_now)
end
def self.for_today
placement_day(0.day.from_now)
end
def self.placement_day date
where(:placement_date => date.to_date)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment