ruby on rails - Scope ordering by reverse order not working -


i have scope:

scope :latest_photos, -> {order(:created_at).reverse_order.limit(10)} 

it's supposed put latest photos in first place right? photos put on last place instead.

i've tried:

scope :latest_photos, -> {order('created_at desc').limit(10)}  

but nothing. ideas? thanks!

edit

something not working here:

routes.rb

get 'spots/ultimos' => 'photos#latest 

photos controller

def latest         @categories = category.all         @zones = zone.all         @photos = photo.latest_photos         @action = 'general'         @photos = photo.paginate(:page => params[:page])         render :index     end 

model

  scope :latest_photos, -> {order(created_at: :desc).limit(10)} 

def latest     @categories = category.all     @zones = zone.all     @photos = photo.latest_photos     @action = 'general'     @photos = photo.paginate(:page => params[:page])     render :index end 

you have assigned @photos variable twice, second assignment overrides previous one. instead do:

def latest     @categories = category.all     @zones = zone.all     @photos = photo.latest_photos     @action = 'general'     render :index end 

the actual value assigned depends on want achieve here. since action called latest , have limit in scope, have assumed don't need pagination here.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -