Reputation: 211
How can i get the img src value from the (= raw post.body) in ruby on rails haml page ? Now i am getting the total contents i.e,
<p>Lorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsum</p>\r\n<p><img style=\"float: right;\" src=\"../../../spree/blog_entry_images/704/large/IMG_4378.jpg?1466600823\" alt=\"\" width=\"404\" height=\"606\" /><img src=\"../../../spree/blog_entry_images/718/large/IMG_4356.jpg?1466608157\" alt=\"\" width=\"405\" height=\"608\" /></p>
I want to show each image in loop. So how can i get this ???
Thanks in Advance.
Upvotes: 0
Views: 212
Reputation: 4156
You can use gem nokogiri to extract any html tag, try following code snippet, you might need to require 'nokogiri'
while try on console
content = Nokogiri::HTML(pass_your_html_content)
srcs = content.css('img').map{ |i| i['src'] }
Upvotes: 1