[Arel]Building query, but can't get a proper output

I have the following code:

  advertisements_arel = Advertisement.order("advertisements.id

DESC").arel
@advertisements = (params[:website_id].present? ?
advertisements_arel.where(:website_id => params[:website_id]) :
advertisements_arel).to_a

It returns a struct Arel::SelectManager::Row data
But I’d like it to return an array of Advertisement objects (like it
would normally do) so I can iterate over it more easily. This is because
kaminari is intergrated into the model Advertisement.
Anyone know how to do that?

El martes 13 de marzo de 2012 15:10:40 UTC+1, Ruby-Forum.com User
escribi:

But I’d like it to return an array of Advertisement objects (like it
would normally do) so I can iterate over it more easily. Anyone know how
to do that?


Posted via http://www.ruby-forum.com/.

If you remove the .arel you get an ActiveRecord::Relation which you can
iterate as if it were an Array, plus you can keep appending .where(…)
as
in your code

Regards.

Right… stupid me…

Thanks anyway :wink:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs