Posterous theme by Cory Watilo

Filed under: cms

How to assign permissions for custom controllers in locomotive cms

In my previous post I've shown how to render locomotive pages from you own controllers, but then I've realised that these custom controllers can be accessed only by the administrators of the site. So how to give mere mortal authors the permissions to edit that content?

Actually quite simply. Locomotive uses Cancan permission gem to handle who can do  what so all I needed to do is to use little bit of meta programming and did once again pointed me into right direction.

I did this:

And woula my Author level users can manage their albums without me. Hope that helps someone figuring locomotive cms out.

How to render locomotive cms pages from your own rails controllers

UPDATE: it turns out all this code only works correctly on ruby 1.9.2, I've tried to deploy this to 1.8.7 ree server and the menu item did not show up in the admin interface and also the permission settings for authors did quite work.

Few days ago I've stumbled on to nice example how to add some custom functionality to your locomotivecms site. As far as I needed to fix and improve myliufoto.lt albums and previously used refinerycms had really undfriendly interface for adding photos I've decided to remake a whole site using locomotive.

After all the admin stuff was done I needed to show the album list and the photo pages. As far as my data was not in locomotive's own content models and I needed custom routing like /portfolio/album-url/3 and so on I could not use default locomotive rendering to do it.

With the help of did (creator of locomotivecms) I've made a custom method that can render any locomotive page with my own instance variables passed to liquid. Locomotive already has all the rendering and variable setting for liquid implemented in Locomotive::Render::InstanceMethods module, so after some wandering around we've decided to base our code on that.

Here's all the code you need to do that:

Basically I've copied the 'render_locomotive_page' method and made it to accept a path for a page i.e. 'portfolio/photo' that would match page's slug in the cms.

To make it all work few small changes needed to be made:

In the render.rb file:
1. params[:path] has to be set to 'path'
2. then the locomotive_context needed to be changed to include controller instance variables so added the method 'my_context' that uses original locomotive method

In the controller you want to use it:
3. your controller should 'include Locomotive::Routing::SiteDispatcher' so that it has access to some locomotive's methods like 'current_site'

Everything else is left to the locomotive to handle so it should not brake unless the whole rendering is rewritten.

 

Launching RefineryCMS on Ubuntu 8.04LTS

I needed a small website for my wife and so I've wondered out to find a tool for the task that would be written in Ruby.

First I've tried to launch Radiant, but had some incompatibilities with library extension and dropped that after 2-3 hours of struggle. Then I've remembered there was another promising Ruby CMS that is RefineryCMS.

It depends on Rmagick and it has rmagick version 2.12.2 in it's Gemfile... which turned out to be the source of a lot of pain as my production server is old and runs on 8.04 LTS Ubuntu. I was running rmagick 2.13.1 on the server with no trouble... but 2.12.2 refused to install saying that:

Can't install RMagick 2.12.2. Can't find the ImageMagick library or one of the dependent libraries. Check the mkmf.log file for more detailed information.

I've strugled with that for 4-5 hours reinstalled two different versions of Image Magick and then it hit me... In the Refinery Gemfile there's a comment above rmagick line that says:

# Specify a version of RMagick that works in your environment:

So it does not care about exact version... after that I've changed to 2.13.1 and it finally WORKED! That was a relief...

But that was not over .. as far as I've translated most of the Refinery to Lithuanian I've had to use git versions of gems and so after deployment I hit:

Please run `bundle install` (Bundler::GitError)

It turns out the only way to cure it is to use bundle install --deployment and to add .bundle/config to git, because in it there's a path to gems so that passenger knows where to look for them. Otherwise gems installed from git are put into different directory and passenger has a hard time finding them.

The resulting website is myliufoto.lt