Easily add the Pagelime CMS to your Rails app.
Pagelime is a simple CMS service that allows you to define editable regions in your pages without installing any software on your website or app.
Simply add a class="cms-editable"
to any HTML element, and log-in to the Pagelime CMS service to edit your content and images with a nice, simple UI.
We host all of the code, content, and data until you publish a page.
When you publish a page, the PageLime CMS pushes the content to your website via secure FTP or an API.
Using the Rails plugin, we pull the new content into your app dynamically via an API.
First, add the cms-editable
class and an id
to make content editable:
<div id="my_content" class="cms-editable">
This content is now editable in Pagelime... no code... no databases... no fuss
</div>
Second, add acts_as_cms_editable
to your controller to display the latest content:
class CmsPagesController < ApplicationController
acts_as_cms_editable
end
Done!
- Pagelime account (either standalone pagelime.com or via the Pagelime Heroku add-on)
- Pagelime Rack gem (
pagelime-rack
)
Edit your Gemfile
and add
gem "pagelime-rack"
gem "pagelime-rails"
then run
bundle install
Edit your config/environment.rb
file and add:
config.gem "pagelime-rack"
config.gem "pagelime-rails"
then run
rake gems:install
(Skip if using Heroku add-on)
If you are NOT using the Pagelime Heroku add-on, set up an account at pagelime.com. Make sure that the "Integration Method" for your site on the advanced tab is set to "web services".
For any controller that renders views that you want editable, add the acts_as_cms_editable
behavior like so:
class CmsPagesController < ApplicationController
# attach the cms behavior to the controller
acts_as_cms_editable
def index
end
end
You can pass an :except
parameter just like with a filter like so:
acts_as_cms_editable :except => :index
Caching and logging are automatically setup using your Rails configuration. You can specify custom caching and logging by adding the following to an initializer file.
Pagelime.configure do |config|
# object that responds to `fetch` and `delete`
config.cache = Rails.cache
# options passed to `fetch(key, options = {}, &block)`
config.cache_fetch_options = { :expires_in => 1.year }
# any standard logger
config.logger = Rails.logger
end
It is highly recommended that you enable server caching to reduce latency on each request when retrieving CMS content. MemCachier has a great Heroku addon for caching if you don't have caching configured.
The Rack::Pagelime
middleware is inserted before Rack::ConditionalGet
to retrieve CMS content before HTTP caching is performed.
Read the pagelime-rack
documentation for more configuration options.
Create some editable regions in your views like so:
<div id="my_content" class="cms-editable">
this is now editable
</div>
The ID
and the class
are required for the CMS to work
Optionally: If you don't want to have your entire controller CMS editable for some reason, you can sorround areas in your view with a code block like so:
<% cms_content do %>
<div id="my_content" class="cms-editable">
hello world
</div>
<% end %>
If you're using the Pagelime Heroku add-on, go to the Heroku admin for your app and under the "Resources" tab you will see the Pagelime add-on listed. Click on the add-on name and you will be redirected to the Pagelime CMS editor. From there you can edit any page in your Rails app!
If you have a standalone Pagelime account, simply go to pagelime.com and edit your site as usual (see Step 2).
Copyright (c) 2013 Pagelime LLC, released under the MIT license