0

In my controller I have:

@payment_types = [['Cash' ,'1'], ['Card', '2']]

What I'm trying to achieve is to show in view Cash and Card while writing on database 1 and 2.

In my view I tried:

<% payment_types.each do |payment_type| %>
  <%= payment_type %>
<% end %>

which shows ['Cash' ,'1'] ['Card', '2']]

How can I show instead in my view Cash or Card?

2 Answers 2

6

I'm not sure if I understand your question, but if you want to show only 'Cash', and 'Card', you can do it by passing another argument (responsible for hash value, I called it _ because it's a convention for unused arguments) to your block, like this:

<% payment_types.each do |payment_type, _| %>
  <%= payment_type %>
<% end %>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes that's what I was looking for. Thanks!
2

You could also do it like this

<% payment_types.each do |payment_type| %>
  <%= payment_type.first %>
<% end %>

2 Comments

Yes this works too, and I can access also to payment_type.second etc.. Good to know.. Thanks!
This way you can add extra content to youre arrays and still can acces this from payment_type

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.