ahmet
ahmet

Reputation: 5005

Getting the contents of a hash

{"test_url"=>"http://test.com/123.jpg"} 

is my output from

<% @results.each do |t| %>
    <%= t.image.extract!("test_url") %>
<% end %>

How can i just get the contents of test_url? so http://test.com/123.jpg

Upvotes: 0

Views: 82

Answers (2)

aguynamedloren
aguynamedloren

Reputation: 2273

<% @results.each do |t| %>
    <%= t.image["test_url"] %>
<% end %>

Upvotes: 1

Ole Riesenberg
Ole Riesenberg

Reputation: 156

#extract! always deletes and returns the key/value pairs for the given key from the Hash.

To delete and only return the value:

<%= t.image.delete("test_url") %>

or, if you just want to get the value:

<%= t.image["test_url"] %>

Upvotes: 4

Related Questions