Calling Jekyll From Ruby/Rails


#1

I’m attempting to call the jekyll binary from a ruby method inside a rails app. Running ‘jekyll new’ and ‘jekyll build’ from the console by hand works fine. Running jekyll new from within ruby works fine but jekyll build brings back this error:

“Configuration file: /Users/x/code/blog-6/_config.yml\n” + “jekyll 3.4.3 | Error: The minima theme could not be found.\n”

I’m thinking this is a problem caused by environment variables or possibly RVM but haven’t had any luck in days of trying to track it down.

Any Ideas?


#2

I think you might need to add ‘minima’ gem to your Gemfile. Since you are calling to Jekyll via command-line from within Rails app your $LOAD_PATH must have path to minima theme… Because you’re spawning a new child process out of your Rails app, that child process inherits all environment variables and imho it is the culprit of the error you’re seeing.

You can try to trace out $LOAD_PATH variable before calling to Jekyll to confirm whether you’re missing path to minima gem or not…

Hope it helps.


#3

Awesome that was exactly it @pabloduo :sunny:

I’ve stuffed the jekyll-required gems into the Rails app’s Gemfile and got it to build successfully. It feels wrong adding the gems into the RoR app’s Gemfile, will I run into further problems if I don’t get ruby to execute in the context of jekyll?


#4

Yay! Glad it helped! :smiley:

Conceptually Jekyll is a Ruby gem and it should be delivering its features in any Ruby-alike environment (including RoR)…

But… Jekyll by default is assumed to be run from the console (your user account must have permissions to do that) and RoR is by default assumed to be run with least privileges. IMHO, these assumptions are conflicting and therefore chances are you might run into some quirks. And if that won’t happen today it well might happen tomorrow, unless that setup is OFFICIALLY supported by Jekyll with corresponding test coverage and validations.

You still can run things your way, as long as it reliably works for you and your customers. :wink:

Hope that makes sense.