0

I am developing an app using Ruby on Rails. In a specific view I have a textarea that uses Bootstrap Markdown.

The problem is that each time I visit that view, the textarea is rendered completely plain, without the Markdown functionality. Hitting F5 (refresh) renders the form correctly.

I tried to clear my browsers cache etc, but no luck. I always have to hit refresh to see the page correctly.

What may cause that?

Edit: I am using this Markdown Plugin

I have also included the js files as stated in this question.

Community
  • 1
  • 1
  • 1
    Are you using turbolinks? If so, try disabling it and check if that solves the problem. – SoSimple May 03 '15 at 13:34
  • If so (the turbolinks part) you'll need to replace the javascript hook `ready` with `page:load` – Mohammad AbuShady May 03 '15 at 13:36
  • Yes I am using turbolinks. I tried to disable it and it worked correctly. @MohammadAbuShady where is the mentioned hook? I can't find how to change it... – Fotis Panagiotopoulos May 03 '15 at 13:57
  • @user3634713, well whatever markdown plugin you are using probably has a javascript code that uses the `ready` callback to start rendering, you need to find it and call whatever method it's calling but using this hook instead, you could add a link to the markdown plugin you are using in your question to get more specific help. – Mohammad AbuShady May 03 '15 at 14:00
  • @MohammadAbuShady I updated the question with links to the plugins. I believe you mean the calls at line 1348 at bootstrap-markdown.js file of the first link, but still I haven't managed to make it work... Any suggestions? – Fotis Panagiotopoulos May 03 '15 at 14:20
  • Ok from what I see, there's a javascript line that you could run by your self, in their `Usage` section, you could add that inside a `page:load` in the pages that uses it, instead of the `data-attribute` – Mohammad AbuShady May 03 '15 at 14:24
  • @MohammadAbuShady Well I just changed the line 1356 using .on('page:load') as you suggested and it worked. Your second proposition may be better regarding code maintenance... Anyway, MohammadAbuShady and SoSimple you both helped me a lot. you can post a complete answer so I can accept it. – Fotis Panagiotopoulos May 03 '15 at 14:30
  • @SoSimple, you can go ahead and post an answer. – Mohammad AbuShady May 03 '15 at 14:32
  • @MohammadAbuShady Thank you, I'll draft one up now. – SoSimple May 03 '15 at 14:35

2 Answers2

1

The turbolinks gem has been known to interfere with other javascript files and it's recommended that you remove it completely unless you really need it.

As Mohammad AbuShady said in his comment, you'll need to edit the part of the javascript files for your markdown that tells the page to start rendering. In your case this involves adding

$("#some-textarea").markdown({autofocus:false,savable:false})

inside page:load on the relevant pages.

SoSimple
  • 701
  • 9
  • 30
0

In case you need turbolinks still, I found this very helpful: JQuery gets loaded only on page refresh in Rails 4 application

I had the same issue and adding jquery-turbolinks gem allowed the bootstrap-markdown editor to load perfectly for me.

Community
  • 1
  • 1
shreddie
  • 11
  • 3