spohlenz / tinymce-rails

Integration of TinyMCE with the Rails asset pipeline
Other
814 stars 257 forks source link

data-mce-src prepending '../..' leading to image 'not found' error #154

Closed sushant2675 closed 9 years ago

sushant2675 commented 9 years ago

Hi,

I am using tinymce-rails 4.1.4 with tinymce-rails-imageupload 3.5.8.3 on Rails 4.1. The image gets uploaded fine and the img tag src is set to the value that I am setting from json response of the imageupload plugin. But tinymce's data-mce-src attribute in the img tag is creating the problem as the html generated in the editor looks like below:

<img data-mce-src="../../assets/my_images/65ba346c-d30a-4ea2-9028-5d3cf75371d4/Pic1.png" 
alt="" 
src="/assets/my_images/65ba346c-d30a-4ea2-9028-5d3cf75371d4/Pic1.png" 
data-mce-selected="1">
</img>

When the above tag is saved in the DB and accessed directly as raw content in a div, the tag becomes:

<img alt="" src="../../assets/my_images/65ba346c-d30a-4ea2-9028-5d3cf75371d4/Pic1.png"></img>

The above change in src does not affect the image's display in the tinymce editor, but the image is 'not found' if I try to display content raw in a div because of the '../..' that has been pre-pended.

How should I handle this issue? If the above img tag were to be:

<img data-mce-src="/assets/my_images/65ba346c-d30a-4ea2-9028-5d3cf75371d4/Pic1.png" 
alt="" 
src="/assets/my_images/65ba346c-d30a-4ea2-9028-5d3cf75371d4/Pic1.png"
data-mce-selected="1">
</img>

without the leading '../..' it would have worked fine for me both while rendering raw and in the editor.

Thanks

sushant2675 commented 9 years ago

Setting relative_urls: false in tinymce init did the trick.

Thanks