Rails - how to move view logic into a helper when iterating through an array of objects -
so in view, displaying prices shirts, belong products category. in view, looking through array of shirts so:
<% @shirts.get_shirts("red", "small").each |shirt| %> <%= shirt.price "> <% end %>
this works want, displaying prices shirts red , small.
however, when try move logic corresponding helper, displays full object data instead of prices. helper code below:
def show_prices(color, size) @shirts.get_shirts(color, size).each |shirt| shirt.price end end
and calling in view so:
<%= show_prices("red","small") %>
what doing wrong in helper? seems should same thing not.
result of each
method collection. want next helper method
def show_prices(color, size) @shirts.get_shirts(color, size).map(&:price).join end
Comments
Post a Comment