In a typical blog app if i do something like:
p = Post.order('created_at DESC').limit(10)
p.from(5)
It raises:
ActiveRecord::StatementInvalid: SQLite3::SQLException: near "5": syntax error: SELECT "posts".* FROM 5 ORDER BY created_at DESC LIMIT 10
I'm trying to get the first five posts in an array and the five next in another array. If i use the .from() on an array it's working fine, i get the elements i want beginning from the number i selected. But if i use the .from() in a view or in a controller it will try to generate a new query instead of apply the .from() on the object/array.
My controller was doing:
@last_ten_posts = Post.order('created_at DESC').limit(10)
And the view:
@last_ten_posts.first(5).each do |post|
@last_ten_posts.from(5).each do |post|
How should i use the .from() method ?
Thanks
EDIT: @Rubyist give remember me the first way i was dealing with the posts, i'm interesting in finding why the .from() doesn't work ?