Home



2018/09 - Misc Rails tips for CKEditor (I hate .gemspec files)

Hi folks,

I've actually lost quite a few hours trying to figure out how to fix problems that appeared for me when installing/using CKEditor with Rails 5. I have a document stored on Google Drive that describes various fixes, steps when upgrading, changes that have to be made when switching between development on my Windows 10 local against my Ubuntu virtual machine, and so on. The purpose of which is fairly obvious, text files are forever and human memory is (very) fallible.

I estimate that I spent about four or five hours trying to remember the "extra bits" that I didn't bother to record between the last time I'd worked on this blog/website (Which I've stolen the term "blogsite" for. Although webopedia and other sources say that I didn't come up with the term. Which is probably more correct than me. Maybe). Usually this is fine because I don't work on several side projects at the same time, but situations in life lead me to work on many, many different things at different times. I'd say that there was a period of about four months between when I started/stopped working on this blogsites current changes, which turned out to cost me an annoying amount of (but avoidable) time.

So I developed all my new features (Fixed a problem where the highlighting wouldn't show up on-screen, added blog post import functionality, added an option for users to submit their email addresses to hear more about my rambling, fixed the tutorial/all posts button, fixed the posts formatting, etc, you get the idea) and noticed that the images had stopped working again. I'd had plenty of trouble during my undergrad thesis trying to get ImageMagick working before, and plenty again when setting up this blogsite, so I wasn't entirely unsurprised. I even had a section that dealt with this kind of problem. But the problem was that they didn't fix this "images not showing up" problem anymore. So I ended up searching for and trying out older fixes that I hadn't needed to use since I originally set up this blog, which also turned out to not be the solution. I deduced that if it wasn't somethingthat could be solved by the means that I had come across so far, then it must not be related to them (So it wasn't a problem with CK Editor itself, and perhaps not ImageMagick itself). 

I ended up trying out a fix for a completely different problem, because at that point I hadn't come across a problem like this in almost a year and genuinely couldn't remember which fix was related to which problem. The fix I focused on was the one I found when developing this blog. I had a dependency problem with the Bcrypt and Devise gems for the active_admin gem, the fix for which was uninstalling the bcrypt gem and reinstalling it with the "--platform = ruby" argument, which is nowadays redundant as a straight-forward bundle install with my current gems version doesn't give me any trouble. So I ended up thinking "Huh, it must be the gem versions". I was getting desperate and never gave enough credit to thinking "Wait, bcrypt and Devise are all just authentication-related gems. They couldn't be causing image problems surely?". But I, in my perpetually sleep-deprived state, was determined to be wrong. I gave up on bcrypt because it honestly wasn't causing issues at all anymore. The server ran fine and I vaguely remembered this problem only stopping the server from starting, never preventing images from appearing.

So I then figured it must be an incompatibility between my current gems versions. I ended up trawling through the hosted version of this blogsite to find the exact gem versions that DEFINITELY DID work, to give me some kind of idea as to what could fix this annoying issue. I had trouble figuring out exactly why my gems were not deleting correctly when I used bundle install and remove my gemfile.lock file, found out that I had to manually delete them under the appdata folder, found out that even THAT wasn't enough and had to delete a bunch of .gemfile files under appdata as well, then finally finished up this process no better off than when I started.

I eventually figured after all this that I could have made changed, way back four months beforehand, that were now preventing me from uploading images correctly. I remembered googling "CKEditor red cross" when I was originally trying to solve this problem, remembering that the images actually were uploading (And that CKEDitor was just reading from the wrong directory), remembered that this problem was actually caused by the models directory being pointing to the wrong location (I have to change the directory when switching between development on Windows 10 and deployment on Ubuntu), and finally made the model change and was able to upload and deploy my changes. All because I started working on these features and had a large gap between that and finishing them.

Lesson learned: Be absolutely ruthless with documentation. Don't make strong assumptions when working with projects that you haven't touched in a while.

Don't make the same mistakes I did!

Good luck!

Marc