ruby - rails if object in an array -
I have to check this, if for each item in @line_items
if it is in a different array @ quote_items
Controller:
DIF index @ line_item = linememe @ @coot_times = quote item See all terminations
:
& lt;% line_item @ line_items% & gt; & Lt;% if @ quote_items.include? (Line_item)% & gt; Line item in line item! & Lt;% else% & gt; Do not quote in line item! & Lt;% end% & gt; ... & lt;% end% & gt;
Is this an easy way to do this? Is included?
The way I want it does not seem to work, that only produces false for me at all times.
You are trying to check that the line item object in the array of @ quote_items is
@ quote_items.include? (Line_item)
which will obviously always be false because your @ quote_items example is an array of the quoteItem objects and @ line_items is an array of example lineItem objects so they always have different objects Are there.
I think that in this situation you may want to compare quote_item and some common feature of line_item. For example, if you want to compare the name attribute, then
quote_item_names = @ quote_items.map (& amp; name)
and then < / P>
& lt;% if quote_item_names.include? (Line_item.name)%> Line item in line item! & Lt;% else% & gt; Do not quote in line item! & Lt;% end% & gt;
Comments
Post a Comment