Best way to display recently changed objects?

I'm trying to create a list of recently changed objects...

but..

@events = Event.find :all, :limit => 2, :order => 'updated_at desc' @videos = Video.find :all, :limit => 2, :order => 'updated_at desc' @recently = [@events, @videos].sort_by(&:updated_at).reverse

gives a..

undefined method `updated_at' for #<Array:0x24ecf30>

Any ideas of best practice for this type of thing?

I'm trying to create a list of recently changed objects...

but..

@events = Event.find :all, :limit => 2, :order => 'updated_at desc' @videos = Video.find :all, :limit => 2, :order => 'updated_at desc' @recently = [@events, @videos].sort_by(&:updated_at).reverse

gives a..

undefined method `updated_at' for #<Array:0x24ecf30>

that's because the elements of the array you are sorting are the 2
arrays you fetched previously

You want something like

(@events + @videos).sort_by(&:updated_at).reverse

Fred

Fred already explained the problem.

Let me add a remark: that code looks like something that belongs to some controller. If that's the case, in a controller finds like those are better encapsulated in the models, using named_scope in recent Rails, or a regular method in previous ones:

   class Event      ...      def recent        find :all, :limit => 2, :order => 'updated_at desc'      end    end

so that the controller just says:

   @recently = (Event.recent + Videos.recent).sort_by(&:updated_at).reverse

-- fxn

def self.recent

Thanks, that works great.

Thanks, yes, you are right.