Raul
Raul

Reputation: 299

Can an instance variable be treated as an array in Ruby on Rails?

Here I am getting values from my model and I am putting it as an instance variable in my controller:

@users = User.where(:approved => true, :enabled => true)

now I want @users to behave as an array so that I can perform the following operation:

@users = @users | current_user 

i.e an array union. any pointers ?

Upvotes: 0

Views: 505

Answers (2)

Raul
Raul

Reputation: 299

this would initialize the @current_user array:

@current_user = [current_user]

then I did

@users = @current_user | @users

and it worked!

Please suggest if you have a better solution.

Upvotes: 0

Mark Fraser
Mark Fraser

Reputation: 3198

@users = User.where(:approved => true, :enabled => true).to_a

Upvotes: 1

Related Questions