Skip to content

Instantly share code, notes, and snippets.

@sbusso
Created April 27, 2012 01:58
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sbusso/2505027 to your computer and use it in GitHub Desktop.
Save sbusso/2505027 to your computer and use it in GitHub Desktop.
Super simple CMS with Rails Admin
rails g model Page title:string content:text slug:string
rake db:migrate
rails g controller Pages --skip-assets
# Add the gem
gem 'rails_admin'
class Page < ActiveRecord::Base
attr_accessible :content, :slug, :title
# add this method for friendly urls
def to_param
slug
end
end
class PagesController < ApplicationController
def show
@page = Page.find_by_slug(params[:slug])
render :inline => @page.content.html_safe, :layout => true
end
end
# add the configuration for editing a page config/initializers/rails_admin.rb
config.model Page do
field :title
field :slug
field :content, :text do
ckeditor true
end
end
# add to your routes:
get "pages/:slug" => "pages#show", :as => 'page'
@sbusso
Copy link
Author

sbusso commented Apr 27, 2012

use page_path(slug) in your views and links

@rceee
Copy link

rceee commented Jan 19, 2013

Nice! This is a workable model that expands on what's in the rails_admin demo app (which doesn't really work); much better. Kudos for this

@Sigularusrex
Copy link

This is nice and simple. one thing though, attr_accessible should be attr_accessor (in rails 4 at least)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment