Converting an array into active record in rails

Converting an array into active record in rails

So this is a common requirement which every one of us have to face once a while.
In my project I was getting the array of result from a modal method i.e backup_projects. Now to apply sorting and pagination I have to convert it into rails active record.

As I could have applied sorting on active records only. So I came across a way as shown below.

     project = Project.backup_projects
      project.map{|i| i.id}
      @projects = Project.where(:id => project)
@projects was an active record thus and served my purpose.
Advertisements

One thought on “Converting an array into active record in rails

  1. how would that help you to hold the sorting?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s