BlogKit, a Plugin to Add a Blog to your Rails App

Posted By Ryan Stout on June 05, 2010

It seems like every project I do needs a blog integrated into it. There are a few ways to setup a blog within an existing site, but I felt like they all were lacking in some large way. Here is what I or others have done to get a blog integrated into an existing site.

Use Twitter

This seems like a popular option for people to update users on their applications, while it works, there are some serious limitations.

Upsides:

  • Super easy
  • fairly well understood

Downsides:

  • 144 character limit
  • different domain, so little value on search engine ranking
  • different look
  • no real comments

Use WordPress.com or other hosted service

This also seems common because it is for the most part easy.

Upsides:

  • Still fairly easy
  • Shared authentication system with other blogs

Downsides:

  • different domain
  • different look
  • different authentication system for comments/posting

Use WordPress Locally

While there are a few Rails blog apps, most of them are lacking and don't have much real support in the rails community, which leaves someone looking to other languages if they want to install a blog app locally.

Again, the common blog app people reach for is WordPress, love it or hate it, its the standard. However, installing locally still leaves us with some issues.

Upsides:

  • Good community support
  • Can be integrated with same look and authentication

Downsides:

  • Requires duplicating layout code/resources to get same look
  • Sharing authentication must be done at the database level
  • Sharing authentication is difficult
  • Requires installing Php

Can't we have it all?

From my point of view, every solution to integrate a blog into an existing rails app is either severely limited, or requires way too much time to setup. Having written a few rails plugins before I thought there has to be a rails plugin that lets me add a blog to my existing rails app. After searching, I was only able to find one called Bloggity, but it seemed to have some limitations:

  • requires attachment_fu
  • not being actively developed
  • doesn't use existing layout or authentication (by default at least)
  • not easy to integrate (imho)

What I think we need

So after looking for a while and using WordPress.com on a few projects, I finally decided I needed to take the time to build a rails blog plugin that meets my requirements.

My goal was to limit the dependencies, and have it degrade gracefully if you don't have a required dependency. So for example, I handle image uploading with paperclip, however if you don't have or want to install paperclip, it disables image uploading. I want it to be easy to install, integrate with your existing layouts and authentication if they are setup in a common way (via authlogic or restful_authenticaiton for example)

I figure to make it easy and useful, it should:

  • Use existing user model and before filters (based on conventions - requre_user, current_user)
  • Use existing application layout (with option to customize)
  • Have easily customizable CSS
  • Have option for markdown (default) or html

Thinking some more I decided that there were a few other features that I thought would be good and that most blogs have:

  • Search engine friendly urls
  • Comments via existing user model
  • Highlights code (with ultraviolet - optional)
  • Akismet (spam filtering) Support (optional)
  • Image and Gravatar support
  • Anonymous Comments (optional)
  • Atom Feeds
  • Tags
  • S3 Image Upload support

After a few weeks of work, I'm happy to present BlogKit

BlogKit

BlogKit supports rails 2 and 3 (via rails 3 branch), ruby 1.8.x and ruby 1.9.

Installing BlogKit is as easy as:

./script/plugin install http://github.com/ryanstout/blog_kit.git
rake db:migrate

or for rails3

./script/plugin install http://github.com/ryanstout/blog_kit.git -r rails3
rake db:migrate

For authentication, having a require_user before filter and a current_user method have become somewhat convention. If you are using something else, you can alias your existing methods and BlogKit will work.

The only dependency is will_paginate, however I'll be removing this requirement shortly.

When you install the plugin, it runs the blog_assets generator and copies over css files and a config file. Everything else stays in the plugin and can be over-ridden by copying it into the /app dir.

A settings file is created at config/blog_kit.yml that lets you customize how the plugin should work.

Once you've set it up, you can see the blog at /blog_posts

If your user model returned by current_user responds true to #admin? then you will see the links to create manage blog posts.

Once thats done you should have a fully functioning blog. You can see public/stylesheets/blog_kit.css for ways to customize the layout of the blog. You can specify a layout just for the blog pages in config/blog_kit.yml, if you want to add a side panel, you can do that there and use the <%= blog_tags_list %> tag to add the list of tags to the layout.

Status

While this project is still early, it should be ready for anyone to drop a blog into their app quickly. Please post any issues to the github page and fork the project and add features as needed.

See the github page for more info


Tags: plugins, rails, blogkit, blog

Showing 20 comments

RizRuinalldup Posted 5 days ago

Hi! my identify is Jully. I would like to meemeet good brat :) This is my homepage - http://jskdh5jkd7djh4.com/l

Ramie Posted 10 months ago

Hi Ryan, here's the rake task I came up with o import Blogger xml blogs into blog kit. Developers will need to adapt to their own user model. All disclaimers etc. apply: https://gist.github.com/920424

Duane Posted 11 months ago

Hi Ryan, Love this plugin! Your writeup about choices, hosting it via wordpress etc... almost exactly mirrors our own thinking, and now we're at the "Can we just whip up our own in Rails?" stage. Question : Under Rails 3, I'm finding that whenever I submit a new blog_post, it is mistakenly handled by #index instead of #create, and thus never created. This is out of the box, I haven't mucked with any routes, but they look about as straightforward as you can get. Any idea why my blog_posts_controller doesn't realize it's supposed to send that POST to create? Thanks!

Ryan Stout Posted 12 months ago

Ramie, if you come up with some importing scripts, feel free to send them my way.

Ramie Posted about 1 year ago

Hi Ryan, we are integrating your great plugin into our rails 3 re-factored web app (along with a cms and forum engine). Just curious: did you think about the task of importing from another blogging engine (like Blogger)? If you haven't already solved this problem, I am turning to that task now, and would be happy to share what I come up with.

Ryan Stout Posted about 1 year ago

@Quadari: Its 'rails plugin install' for rails3 @Giang: If you have an def admin? method on the user model, have it return true on your user and it will show the links to create new posts.

Trey Posted about 1 year ago

This is a great plugin! It was very easy to install. I'm using a different authentication plugin so I had to change the admin? calls to is_admin? but that was easy. Anyone using this will need some kind of authentication running so the admin calls work. Oh, and for anyone playing with the yml file, make sure you don't leave any spaces before the variables or you'll get a null reference when you go to the blog_posts page.

Giang Nguyen Posted over 1 year ago

hi Ryan. I'm running Ruby 1.8.7, Rails 2.3.8, with will_paginate gem, without blueCloth/UltraViolet. after installing Blog_kit plugin and adding before filter for required_user and a method named current_user (all are placed in application_controller.rb) I go to http://localhost:3000/blog_posts and see this: "No Blog Posts There are currently no blog posts, please check back shortly." Is there any further document on this plugin? how do I create posts? Thanks Ryan -Giang

Quadari Posted over 1 year ago

So I'm excited to try this, but can't figure out how to get it working. I'm running Rails 3.0.1, Ruby 1.9.2. I created a brand new rails site: > rails new newsite --database=mysql Then I cd into it: > cd newsite I tried running the command you suggest: > ./script/plugin install http://github.com/ryanstout/blog_kit.git -r rails3 -bash: ./script/plugin: No such file or directory So that clearly doesn't work. I think what you mean is: > rails plugin install http://github.com/ryanstout/blog_kit.git -r rails3 That doesn't return any error, but then again it also doesn't seem to do anything at all. I don't have any new files in my directory anywhere that I can find. I'm probably doing something stupid wrong, so any help is appreciated. Thanks!

PCoder Posted over 1 year ago

I thought this plugin is one of the most sought plugins in rails. I am ecstatic to find your plugin right away, Thank you Ryan. I am pretty much sure, the current page is also using the same plugin :)

lgs Posted over 1 year ago

How can I simulate current_user.admin? - I've not an admin? action I just have two private method require_photographer and current_photographer in application_controller.rb which aliasing this way: alias :require_user :require_photographer alias :current_user :current_photographer My model Photographer doesn't have administration concept photographer.rb So when I go for /blog_posts I get the error "undefined method `admin?' for #<Photographer:0xb63d8644>" If I remove && current_user.admin? from app/views/blog_posts/_admin_links.html.erb leaving just <% if current_user %> I get a blank page ... Any suggestion ? Thanks in advance Luca

Timofey Sitnikov Posted over 1 year ago

Ryan I tried everything, but, after installing I copied the file index.html.erb from the plugin folder to the /app/views/home, and I run the server I get the following message: Missing template home/_admin_links.erb in view path app/views:vendor/plugins/blog_kit/app/views I am probably not registering something right, Please give me a hint. I searched all over for the answers. I am very new to ruby. Thank you

Corey Posted over 1 year ago

Hey Ryan, Newbie trying to install the rails 3 branch to no success. On Windows, Rails 3.0.0.beta4, ruby 1.9.1p378. I have been able to clone the git repository using: git clone git://github.com/ryanstout/blog_kit.git but it appears that it's the wrong branch. I've tried using your switch -r rails3, with no success and according to the git commands, I should use the switch -b rails3 (which doesn't produce an error, but seeemingly pulls the wrong branch). Having successfully pulled cloned the git repository (albeit the wrong branch), the .yml file is not located in the config directory, rather in the test directory under the filename "database.yml". Any advice for a newbie? Thanks for supporting the community!

Ryan Stout Posted over 1 year ago

Steve, Sorry, I had the wrong url in the readme, it should work now. The init.rb catch thing is if you have a really old version of rails. It should work for anything in 2.3.x, if it doesn't let me know.

Steve Alex Posted over 1 year ago

Still a newbee with Ruby (other than writing my own functions/methods) but it looks like in your install.rb that if the exception is raised in the call to Rails::Generators.invoke('blog_assets') it will print that error message and eat the exception and the second exception will not print that it was installed and print rails generate blog_assets. I did that and it installed. Now just going thru some configuration issues.

Steve Alex Posted over 1 year ago

I tried to install the rails 3 version and got a warning (your rails3 install is also wrong in the post) info:gg3 salex$ rails plugin install http://github.com/ryanstout/blog_kit.git -r rails3 Initialized empty Git repository in /Users/salex/work/gg3/vendor/plugins/blog_kit/.git/ warning: Option "depth" is ignored for http://github.com/ryanstout/blog_kit.git Then after the download, got and error/exception: Could not find generator blog_assets. Which was called in you install.rb

Ryan Stout Posted over 1 year ago

Andy, I've also had sites where I want the ability to make "pages", but managed with a rails engine. I see no reason why we couldn't add that. Right now there's a few other features I need to get out first, like e-mail when someone replies to your comments :-) I think it would be easy to add down the road though. Feel free to fork and add stuff. Ryan

Andy Posted over 1 year ago

To clarify my earlier comment, I think blogkit seems like a much cleaner way to implement a blog or CMS type system into a site rather than building the entire site around a full cms like refinery or radiant.

Andy Posted over 1 year ago

This sounds like it has a lot of promise. Quick question, do the search engine friendly URL's totally custom slugs? I am wondering if its possible to use this plugin as a CMS type front for the marketing portion of a site. Would that be something that would work or is this plugin more geared towards date sorted posts? If possible, a nice feature might be to have "pages" like wordpress does for evergreen content. Shoot me a note if you'd like some help. I could contribute to some of these features. It's been my experience that integrating a CMS into an existing project, or having to develop a rails project around a CMS framework is always a little messy.

Dennis Posted over 1 year ago

wish I had this six months ago

Post a Comment