Can a Rails app and a Jekyll blog live together? - ruby-on-rails

I have a Rails app and I want to add a blog feature; my idea is to use Jekyll which is a great blog tool, I just need to figure out if it's possible to use http://my.app.com/blog as a url (knowing that Jekyll will run its own server process with its own url).
Does anybody know of a way to accomplish this? It'd be great to be able to do so. Best regards!

... just need to figure out if it's possible to use http://my.app.com/blog
as a url (knowing that Jekyll will run its own server process with its own url).
While jekyll's web server works, it will be probably easier, simpler and safer to use your rails app's webserver for serving all pages.
The simplest way of doing what you want is hooking a jekyll invocation to your server's git repository, so jekyll's static content is added automatically to your rails app's public/blog/ directory every time there is a push.
Create a symbolink link called public/blog inside your app's public folder. Make it point to the generated _site folder of your jekyll repository.
On the git repository that controls the contents of the jekyll blog, add a post-receive hook that does the following:
#!/bin/sh
rm -rf _site
jekyll
Those are the basic steps. You might have to configure the read permissions properly, ignore the /blog/ link if you are using an SCM (like you should) and automate the link creation if you are using Capistrano or Vlad for deploying.
There are other alternatives, like using a real folder instead of a symbolic link and having jekyll generate stuff directly there, but I feel the one I'm presenting is the cleanest.

Would you be using nginx to reverse-proxy the Rails app? If so, you should be able to just carve out an exception so /blog is served directly by nginx instead of forwarded to Rails.

Check out this gem: https://github.com/zbruhnke/bloggy
And this blog post about it: https://blog.engineyard.com/2012/introducing-bloggy-a-simple-way-to-add-a-jekyll-blog-to-any-rails-application

I had the same problem a few weeks ago. If you really have to use Jekyll, I think the best solution is to use the already mentioned Bloggy gem.
However, I wasn't satisfied with this solution, because you still have to duplicate or synchronize a lot of things like templates, routes, stylesheets, and so on. So I decided to implement my own simple Jekyll-like blog functionality in Rails.
You can find my article describing the implementation here: Create a simple Jekyll-like blog in your Rails 4 app.

Related

Ruby on Rails with Github Pages

I am attempting to host a project using Github pages. As I understand it, Ruby on Rails cannot be run on GH-Pages, with the exception of using Jekyll. My project is not a blog, and therefor Jekyll seems like overkill. Is there any other way to deploy to GH-Pages? Is there another way to generate a static site from my Ruby on Rails app that would allow for easier deployment?
Thanks for any and all input.
I'm afraid not. Rails is a dynamic system, meaning that the pages are generated from templates combined with data. GH-pages only servers static HTML, so even if you put static content into Rails, you would not be able to run the scripts that serve it.
Use Jekyll or Middleman to make a static site. If you really need Rails, use Heroku's free plan.
You could use actionpack-page_caching to generate page-level caches in the public folder of your Rails application, then add those generated pages to your GitHub Pages repository.
However, this entirely defeats the purpose of using something like Rails. Why don't you just create static pages directly and upload those to your GitHub Pages repo?

Using CodeKit 2 with Wordpress/Bootstrap via Bower

This may be a really dumb question but I've been searching the interwebs and haven't really found much helpful information. I have CodeKit 2 and I want to use Wordpress and Bootstrap in a project. I've never used Bower before but it looks really cool and I thought I'd give it a shot with CodeKit. I installed Wordpress, JQuery, and Bootstrap through the assets tab in my project and they installed into bower_components. In the video from Bryan Jones showing off Bower, he says not to move anything out of that folder or CodeKit won't see it as an asset anymore.
So my question is: how do I go about building my project from here? Obviously I don't want to have to run from the bower_components folder to do everything. In the Bower docs it says the easiest way is to just statically link the components you want. But I don't really understand how that would work with Wordpress and it seems like there'd be a better way to do it with CodeKit.
Thanks for the help!
There is no need to use Bower to manage wordpress, since wordpress can update itself very easily.
I think the best approach to building a WP site with Codekit is described in this tutorial: Use CodeKit 2.0 for Local WordPress Development.
Basically:
setup wordpress locally, any way you like, and use MAMP or AMPPS to serve the site.
drag your theme folder into Codekit - the theme is the project.
In the Browser Refreshing section of your project settings, use the external server option. Paste in the local URL for your new WP site.
Here's an article with some details.
Basically you just need to install bootstrap.less and variables.less in your /less folder, and then point your #import commands to your /bower_components folder. While you technically are running things out of /bower_components, after it's set up, you'll never know the difference.
The most useful thing about having wordpress connected to Bower is that you can just get the files downloaded quickly without having to grab the latest zip.
It makes sense to move the wordpress files to the top level, or where ever you are used to putting them.

Testing Rails Project/Application Template

There's every chance I've approached this entirely in the wrong way which might be why I'm struggling to find an answer, as is typically the way with Rails.
For clarity, I'm referring to the -m option of "rails new", eg.
rails new [new-project] -m [this is where my template goes]
I've created a project/application template to speed up the creation of a specific project type, with the view that further projects/products will have their own template also.
The template adds in the relevant gems and does a bit of housework to tidy up the output of the gem installation (moving JS/CSS files to /vendors, for example) as well as copying over a generator that gives the option to expand the project further.
I'm struggling to understand if there is a way to test that the project template is working as expected and copying the correct files.
Have I approached this in the correct manner, and is there a way to test project/application templates?
Edit - Further research is suggesting that an Engine may be a better solution. Is that accurate?
A Rails Engine is a way to package some application or application subset so that it is easy to share with other applications. Basically, if you have some models and controllers that can be shared by multiple applications, you can use an Engine. This sounds a lot like what you described as a project template. Engines can be packaged as gems, gems can automatically behave as Engines, include rake tasks, hook into Rails initialization, and more, so why not take advantage of Other People's Work if you can?

Locomotive CMS with Rails - location for liquid templates

I'm new to both Ruby on Rails and Locomotive CMS, but I'm just starting to create my first site with them.
I've got the engine running in a full Rails app (I'm going to need to deploy it on our own server later on). But it's just spitting out the 'Template' content defined through the admin interface, without any other template/content around it.
I can 'fix' it by shoving the html for the whole page in through this input field. But that's not right, surely? The Getting Started guide talks of putting the templates in the filesystem, at something like: Pages/index/first page. "All pages are inherited from index". I have an index.liquid under views/pages but it's not picking that up... (I've tried a couple of other locations too).
I'm sure this is a dumb question, but please could someone tell me where to put my template in the file system? Or how to point Locomotive to pick it up from the right place?
(I did get the file system liquid template working by defining it through the Rails way, with a route, a controller and adding a liquid template initializer I found here. But then it's missing the variables that should come from the CMS content).
I'm loading the site using bundle exec unicorn_rails. And I'm using Rails v3.2.13, Ruby v1.9.3 and Locomotive_cms v2.2.2.
Thanks!
I'm Didier from LocomotiveCMS.
LocomotiveCMS is a little bit different from the other CMS, in a sense, we offer a tool named Wagon to manage your site locally without having to install mongodb, rails and some other components.
Another huge benefit is that you can write your templates in HAML and your CSS in SASS/ SCSS or Less (we embedded Compass as well) and with our preferred texts editor (editing a whole site in a browser is a nightmare).
That's a nice eco-system in order to be super efficient when it comes to develop a LocomotiveCMS site.
Once you're done with your local work, you can deploy your site to a remote LocomotiveCMS engine in a similar way you push your application to Heroku. Actually, pushing a site will create the back-office for the final end user.
I suggest you to read that page.
http://doc.locomotivecms.com/guides/get-started/requirements
and this one too
http://www.locomotivecms.com/tour
Our message is still not clear on our official website but believe me, we are working to make it better.
Hope it will help you !
Didier

Export my Rails site to Phonegap

I want to use Phonegap for create light cellular version of my site.
Is there any way to save all my HTML`s and assets (after merge all the partials, create the entire assets pipeline items and convert haml and coffees to html and javascript)?
I want to use Rails for writing my client side code and save it.
Thanks!
It depends on the site - if it is mostly static content it should work, but any user interaction will need to be built knowing that the server won't be there when the app runs. Using rails as a compiler for something designed as a phonegap app will work a lot better than trying to package an existing website.
Actually generating the static site is easy enough though:
wget -m -nH www.example.com

Resources