Rails: Appending models to collection
I'm trying to conditionally build up a list of models. I.e.
@items = []
if some_condition
@items << MyModel.where(...)
end
if another_condition
@items << MyModel.where(...)
end
...
This isn't working. It will actually build up an array of the correct
objects but when I access fields and relationships of items in the array,
they are 'not found'. I tried a few other things like @items =
MyModel.none and @items = {} and .merge but none work. I cant seem to
figure this out.
What is the best way to conditionally build up a collection like this?
No comments:
Post a Comment