ruby on rails - replace tags in text with images -


i have text ##imageset## tags replace actual imageset images (image_tag).

this is, view code looks like:

    <% @topictext = topic.text.gsub!(/##imageset##/).with_index { |iset,i|           if topic.topic_imagesets.includes(:imageset).order(:position)[i]            topic.topic_imagesets.includes(:imageset).order(:position)[i].imageset.imageset_pictures.order(:position).each |pic|               '<span>'+image_tag(pic.picture.image.thumb)+'</span>’            end         end      } %>      <%= @topictext.html_safe if @topictext %> 

the result is, tags replaced |pic| records of imagesetpictures , not span actual imageset_pictures.picture image_tag:

...takimata sanctus est lorem ipsum dolor sit amet. [#<imagesetpicture id: 269, imageset_id: 46, picture_id: 280,...>, #<imagesetpicture id: 268, imageset_id: 46, picture_id: 236,...>] lorem ipsum dolor sit amet, consetetur ... 

here solution came with:

<% @topictext = topic.text.gsub!(/##imageset##/).with_index { |iset,i|    if topic.topic_imagesets.includes(:imageset).order(:position)[i]      topic.topic_imagesets.includes(:imageset).order(:position[i].imageset.imageset_pictures.order(:position).map{ |p|         '<span>'+image_tag(p.picture.image_en.thumb)+'</span>'}.join("")    end } %>  <%= @toptext.html_safe if @toptext %> 

probably not elegant, works fine me.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -