将ruby数组中的元素转换为字符串

时间:2021-11-04 21:45:12

I am getting an array with a single element in it, ["http://i.foobar.com/This-Is-The-Remainder-Of-The-Link.jpg"] and I'm trying to render it as just the URL to display an image. Any thoughts on the best way to do this? Currently when I render it in HTML I get ["http://i.foobar.com/This-Is-The-Remainder-Of-The-Link.jpg"]

我得到了一个数组,其中只有一个元素[“http://i.foobar.com/this - is- the - ever - of - link.jpg”],我试图将它呈现为显示图像的URL。有什么好办法吗?目前,当我在HTML中渲染它时,我就得到了[" http://i.foobar.com/this - is- the - only - link.jpg"]

1 个解决方案

#1


8  

You should just be able to pull the first element. You can do this by doing the following.

你应该能够拉出第一个元素。您可以这样做。

a = ['http://someurl.com/somepath']
a.first

or

a = ['http://someurl.com/somepath']
a[0]

#1


8  

You should just be able to pull the first element. You can do this by doing the following.

你应该能够拉出第一个元素。您可以这样做。

a = ['http://someurl.com/somepath']
a.first

or

a = ['http://someurl.com/somepath']
a[0]