# Extension Docs

**URL:** <https://www.ruby-forum.com/t/extension-docs/142899>\
**Category:** Radiant CMS\
**Created:** [July 13, 2008, 1:30am UTC](https://www.ruby-forum.com/t/extension-docs/142899 "2008-07-13T01:30:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Gehring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@Andrew\_Gehring](https://www.ruby-forum.com/u/Andrew_Gehring)\
**Post date:** [July 13, 2008, 1:30am UTC](https://www.ruby-forum.com/t/extension-docs/142899/1 "2008-07-13T01:30:10Z")

</div>

Are there any docs, anywhere, on creating an extension beyond the tag  
example under the “summer reboot”.

I’ve created my extension, but can’t find anything on building a admin  
interface.

The instructions for creating a admin interface on the wiki don’t work  
(aged)…

Thanks,  
Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_Gehring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@Andrew\_Gehring](https://www.ruby-forum.com/u/Andrew_Gehring)\
**Post date:** [July 13, 2008, 3:41am UTC](https://www.ruby-forum.com/t/extension-docs/142899/2 "2008-07-13T03:41:44Z")

</div>

I forgot to point out that the extension includes routes for the  
public-facing part of the site directory. That block should look like  
this:

define\_routes do |map|  
map.with\_options(:controller =\> ‘admin/site’) do |controller|  
controller.site\_index ‘admin/sites’, :action =\> ‘index’  
controller.site\_edit ‘admin/sites/edit/:id’, :action =\> ‘edit’  
controller.site\_new ‘admin/sites/new’, :action =\> ‘new’  
controller.site\_remove ‘admin/sites/remove/:id’, :action =\>  
‘remove’  
end  
end

–  
Tim

---

<div class="post-metadata">

**Author:** ![Andrew\_Gehring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@Andrew\_Gehring](https://www.ruby-forum.com/u/Andrew_Gehring)\
**Post date:** [July 13, 2008, 3:38am UTC](https://www.ruby-forum.com/t/extension-docs/142899/3 "2008-07-13T03:38:12Z")

</div>

On Sat, Jul 12, 2008 at 7:29 PM, Andrew Gehring  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Andrew  
> I don’t know of any particular examples per se, but I took a peek at  
> the code for a few different extensions to get an idea of how it’s  
> done. I made a very simple extension to manage a website directory  
> (just one model, one controller, and two views–index and edit). The  
> key is using Radiant’s Admin::AbstractModelController.

I would post the extension on GitHub, but it seems to be down for  
maintenance at the moment. Here’s the code for the whole extension:

# ./site\_directory\_extension.rb

class SiteDirectoryExtension \< Radiant::Extension  
version “1.0”  
description “Adds a website directory to Radiant”  
url “[http://nams-cms.org](http://nams-cms.org)”

define\_routes do |map|  
map.namespace(:admin) do |admin|  
admin.resources :sites  
end  
map.with\_options(:controller =\> ‘sites’) do |sites|  
sites.search\_sites ‘sites/search’, :action =\>  
‘search’  
sites.sites ‘sites’, :action =\>  
‘index’  
end  
end

def activate  
admin.tabs.add “Sites”, “/admin/sites”, :after =\> “Layouts”,  
:visibility =\> [:all]  
end

def deactivate  
admin.tabs.remove “Sites”  
end

end

# ./db/migrate/001\_create\_sites.rb

class CreateSites \< ActiveRecord::Migration  
def self.up  
create\_table :sites, :force =\> true do |t|  
t.string :title, :url, :null =\> false  
t.string :description

```
  t.timestamps
end
# this part loads data from a fixture... like a bulk import of 

```

defaults  
yml =  
YAML.load\_file(“#{RAILS\_ROOT}/vendor/extensions/site\_directory/db/bootstrap/sites.yml”)  
yml.keys.each do |key|  
Site.find\_or\_create\_by\_title({  
:title =\> yml[key][‘title’],  
:url =\> yml[key][‘url’],  
:description =\> yml[key][‘description’]  
})  
end  
end

def self.down  
drop\_table :sites  
end  
end

# ./app/controllers/admin/sites\_controller.rb

class Admin::SiteController \< Admin::AbstractModelController  
model\_class Site  
only\_allow\_access\_to :new, :edit, :remove, :upload,  
:when =\> [:developer, :admin],  
:denied\_url =\> { :controller =\> ‘sites’, :action =\> ‘index’ },  
:denied\_message =\> ‘You must have developer or administrator  
privileges to perform this action.’

def index  
# this depends on the will\_paginate plugin… I included it as a  
submodule using git submodule add  
git://github.com/mislav/will\_paginate.git  
/vendor/plugins/will\_paginate  
# I executed that git command from the site\_directory extension’s  
root, so will\_paginate is a submodule of the extension, not of the  
radiant install  
@sites = Site.paginate :all, :page =\> params[:page], :order =\>  
(params[:order\_by].nil? ? ‘title ASC’ : params[:order\_by])  
end

end

# ./app/models/site.rb

class Site \< ActiveRecord::Base  
acts\_as\_ferret :fields =\> [:title, :url, :description]  
end

# ./app/views/admin/sites/index.html.haml

- content\_for ‘page\_css’ do  
:sass  
.pagination  
margin: 25px 0  
// more CSS removed for brevity

%h1 Sites

= will\_paginate @sites

%table#snippets.index{:cellspacing=\>“0”, :border=\>“0”,  
:cellpadding=\>“0”}  
%thead  
%tr  
%th.user= link\_to\_unless\_current(‘Title’, site\_index\_url) {  
link\_to\_unless\_current(‘Title’, :order\_by =\> ‘url DESC’) }  
%th.user= link\_to\_unless\_current(‘URL’, :order\_by =\> ‘url ASC’)  
{ link\_to\_unless\_current(‘URL’, :order\_by =\> ‘url DESC’) }  
%th.modify Modify  
%tbody  
- @sites.each do |site|  
%tr.node.level-1  
%td.user= link\_to site.title, site\_edit\_url(:id =\> site)  
%td.user= link\_to site.url, site\_edit\_url(:id =\> site)  
%td.remove  
= link\_to image(‘remove’, :alt =\> ‘Delete Site’),  
site\_remove\_url(:id =\> site)

= will\_paginate @sites

%p  
= link\_to ‘New Site’, site\_new\_url

# ./app/views/sites/edit.html.erb

# this is in ERB because I get a undefined method error when I try to

use HAML… don’t know why

# \<%= @site.new\_record? ? 'New' : 'Editing' %\> Site

\<% form\_for(@site, :url =\> admin\_sites\_path) do |f| %\>

| \<%= label 'site', 'title' %\> | \<%= text\_field 'site', 'title', :class =\> "textbox" %\> | The title text will appear first as the blue link to the site |
| \<%= label 'site', 'url' %\> | \<%= text\_field 'site', 'url', :class =\> "textbox" %\> | The url will appear in green at the bottom of the site's listing |
| \<%= label 'site', 'description' %\> | \<%= text\_area 'site', 'description', :style =\> "width: 100%;", :rows =\> "3" %\> | The description will appear in black between the title and URL. |

 \<%= updated\_stamp @site %\> 

\<%= save\_model\_button(@site) %\> \<%= save\_model\_and\_continue\_editing\_button(@site) %\> or \<%= link\_to "Cancel", site\_index\_url %\>

\<% end %\>

Hopefully that should be enough to get you started.

–  
Tim
