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:


…/extensions/user_status/user_status_extension.rb

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’
end
end


end


…/extensions/user_status/app/controllers/foo_controller.rb

Have empty action that should point right to view

def bar
end


…/extensions/user_status/app/views/foo/bar.rhtml

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:

layout(:from_db)

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.

Matt,

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

Sean

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 http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment…
Exiting
./script/…/config/…/vendor/radiant/vendor/rails/activesupport/lib/active_support/dependencies.rb:477:in
const_missing': uninitialized constant ShareLayoutsExtension::ApplicationController (NameError) from /home/mhughes/work/iona/foo/vendor/extensions/share_layouts/share_layouts_extension.rb:11:inactivate’
from
./script/…/config/…/vendor/radiant/lib/radiant/extension.rb:39:in
activate' from ./script/../config/../vendor/radiant/lib/radiant/extension_loader.rb:118:inactivate’
from
./script/…/config/…/vendor/radiant/lib/radiant/extension_loader.rb:106:in
activate_extensions' from ./script/../config/../vendor/radiant/lib/radiant/extension_loader.rb:97:inselect’
from
./script/…/config/…/vendor/radiant/lib/radiant/extension_loader.rb:97:in
activate_extensions' from ./script/../config/../vendor/radiant/lib/radiant/extension_loader.rb:42:inrun’
from
./script/…/config/…/vendor/radiant/lib/radiant/initializer.rb:45:in
initialize_extensions' ... 31 levels... from ./script/../config/../vendor/radiant/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:inrequire’
from
./script/…/config/…/vendor/radiant/vendor/rails/railties/lib/commands/server.rb:39
from script/server:3:in `require’
from script/server:3

Any ideas?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs