Dynamic content in Extension (Forms in Radiant)

I currently have two Rails apps for my site: one Radiant that serves
the static context and a regular Rails app that does forms and
authentication. Apache sits in front and figures out which app gets
which URL.

It’s becoming a problem – as you can imagine – since both apps need
to look the same. What I’d really like to do is merge the dynamic
functionality into an extension and use Radiant to wrap the dynamic
content with the specified layout.

I’ve read the tutorial on creating extensions and have already created
a custom tag or two. But I can’t figure out how to use my layout when
rendering from my extension:


Define a new custom route

class UserStatusExtension < Radiant::Extension

define_routes do |map|
map.with_options(:controller => ‘foo’) do |foo|
foo.bar ‘foo/bar’, :action => ‘bar’



Have empty action that should point right to view

def bar


Hello from Bar!

Now when I hit my Radiant app with: http://localhost:3000/foo/bar
“Hello from Bar!” is rendered, but it is rendered using the Radiant
admin layout (in radiant/app/views/layouts/application.rhtml.
However, I want to be able to specify (either in my controller or my
view) to use the custom layout that is being pulled from the Radiant
database. For example, can I do this in my controller:


Does this make sense? Is anyone else mixing apps like this? Is
anyone doing forms in Radiant and how are you going about it?

Thanks a lot. I hope to add to the site’s documentation once I get my
thoughts together and get through this project.


Check out the “share_layouts” extension in the core repository. It lets
you specify a Radiant layout to use when rendering your standard Rails


Wow that is exactly what I was looking for :slight_smile:

I tried creating a new radiant app, froze to edge, and added the
extension. When I start up, I get this error:

[email protected]:~/work/iona/foo$ script/server
=> Booting Mongrel (use ‘script/server webrick’ to force WEBrick)
=> Rails application starting on
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at
** Starting Rails with development environment…
const_missing': uninitialized constant ShareLayoutsExtension::ApplicationController (NameError) from /home/mhughes/work/iona/foo/vendor/extensions/share_layouts/share_layouts_extension.rb:11:inactivate’
activate' from ./script/../config/../vendor/radiant/lib/radiant/extension_loader.rb:118:inactivate’
activate_extensions' from ./script/../config/../vendor/radiant/lib/radiant/extension_loader.rb:97:inselect’
activate_extensions' from ./script/../config/../vendor/radiant/lib/radiant/extension_loader.rb:42:inrun’
initialize_extensions' ... 31 levels... from ./script/../config/../vendor/radiant/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:inrequire’
from script/server:3:in `require’
from script/server:3

Any ideas?