0

Hi How do i display the value of domain from this array: {:domain=>"www.domain1.com"}, {:domain=>"domain1.com"}, {:domain=>"www.domain2.com"}

I have tried this:

<% @domains.each do |d| %>
    <%= d %><br />
<% end %>

That displays this:

domainwww.shopcms.dk

domaindomain1.com

domainwww.domain2.com

I have also tried to get valeu of domain like this <%= d.domain %> That gives me an error.

Obviously I want to only display the Domain like www.domain1.com

2 Answers 2

1
<% @domains.each do |d| %>
  <%= d[:domain] %><br />
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

1

since each element is a hash, if you are sure it only contains one key, you can use

d[:domain] 

to get the value and print it.

1 Comment

Thank you. What will happen i theres more than one value? And what can I do to make sure it always only display the hash value of :domain?

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.