andkjaer
andkjaer

Reputation: 4065

rails 3 array display value

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

Upvotes: 0

Views: 1006

Answers (2)

Bohdan
Bohdan

Reputation: 8408

<% @domains.each do |d| %>
  <%= d[:domain] %><br />
<% end %>

Upvotes: 1

nonopolarity
nonopolarity

Reputation: 150956

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.

Upvotes: 1

Related Questions