Rails Support Extension
Extending Radiant via the standard Rails action pack is a bit painful right now cause it's not easy to re-use the Radiant Layouts.
This Radiant Extension allows you to create Radiant Extensions that can use the normal Rail action pack to create rich database driven application but which are still tightly integrated via the Radiant layout system.
Quick Usage
Once this extension is installed, update your controllers so that they extended SiteController. This extension adds a radiant_render method to the SiteController which is identical to the standard Rails render method except that it uses Radiant to layout the view.
For example, app/controllers/sample_controller.rb:
class SampleController < SiteController
def index
radiant_render :layout=>"path/to/page"
end
endThe above will look up the Radiant page that maps to URL "path/to/page" and use that as the template for rendering the content of the rendered rhtml view. Instead of using the page's body part, the result of rendering the rhtml view will be used as the body.
If layout is not specified, it uses the layout of the root page.
This extension also adds a helper to include snippets from Radiant
For example, app/views/sample_controller/index.rhtml:
<h1>How to include a snippet:</h1>
<%= snippet("welcome")%>Detailed Example
For those folks having problems getting started with this extension, I recommend you download and install the following extension which show you how to use the rails_support: http://radiant-rails-support.googlecode.com/svn/trunk/extensions/rails_support_example
These are the steps that were taken to build that example:
1. First generate the extension and example controler
C:\radiant>ruby script\generate extension rails_support_example
create vendor/extensions/rails_support_example/app/controllers
create vendor/extensions/rails_support_example/app/helpers
create vendor/extensions/rails_support_example/app/models
create vendor/extensions/rails_support_example/app/views
create vendor/extensions/rails_support_example/db/migrate
create vendor/extensions/rails_support_example/lib/tasks
create vendor/extensions/rails_support_example/test/fixtures
create vendor/extensions/rails_support_example/test/functional
create vendor/extensions/rails_support_example/test/unit
create vendor/extensions/rails_support_example/README
create vendor/extensions/rails_support_example/Rakefile
create vendor/extensions/rails_support_example/rails_support_example_extension.rb
create vendor/extensions/rails_support_example/lib/tasks/rails_support_example_extension_tasks.rake
create vendor/extensions/rails_support_example/test/test_helper.rb
create vendor/extensions/rails_support_example/test/functional/rails_support_example_extension_test.rb
C:\radiant>ruby script\generate extension_controler rails_support_example example
exists app/controllers/
exists app/helpers/
create app/views/example
exists test/functional/
create app/controllers/example_controller.rb
create test/functional/example_controller_test.rb
create app/helpers/example_helper.rb
C:\radiant>2. Add a route in the rails_support_example.rb to your example controller:
define_routes do |map|
map.connect 'example/:action/:id', :controller => 'example'
end3. Update your controller so that it extends SiteController
4. Add the index action to the example controller
def index
radiant_render
end5. Add a the app\views\example\index.rhtml view file:
<p>
Hi this file is "<%= h __FILE__ %>"
</p>
<p>
Please define a snippet called "welcome", and it will be rendered after this:
</p>
<p>
<%= snippet("welcome") %>
</p>6. Start up radiant and browse the http://localhost:3000/example