0

So in my view, I am displaying the prices for Shirts, which belong to a Products category. In my view, I am currently looking through an array of shirts like so:

<% @shirts.get_shirts("red", "small").each do |shirt| %>
  <%= shirt.price ">
<% end %>

This works just like I want, displaying only the prices for shirts that are red and small.

However, when I try to move this logic into the corresponding helper, it displays the full object data instead of just the prices. My helper code is below:

def show_prices(color, size)
@shirts.get_shirts(color, size).each do |shirt|
  shirt.price
end
end

and I calling it in the view like so:

<%= show_prices("red","small") %>

What am I doing wrong in the helper? It seems like it should just do the same thing but it is not.

1 Answer 1

2

Result of each method is collection. Probably you want next helper method

def show_prices(color, size)
  @shirts.get_shirts(color, size).map(&:price).join
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.