Created
April 27, 2012 01:58
-
-
Save sbusso/2505027 to your computer and use it in GitHub Desktop.
Super simple CMS with Rails Admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails g model Page title:string content:text slug:string | |
rake db:migrate | |
rails g controller Pages --skip-assets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add the gem | |
gem 'rails_admin' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Page < ActiveRecord::Base | |
attr_accessible :content, :slug, :title | |
# add this method for friendly urls | |
def to_param | |
slug | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PagesController < ApplicationController | |
def show | |
@page = Page.find_by_slug(params[:slug]) | |
render :inline => @page.content.html_safe, :layout => true | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add to your routes: | |
get "pages/:slug" => "pages#show", :as => 'page' |
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
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
use page_path(slug) in your views and links