I wanted to code some new features for one of my Radiant sites but I didn't really want to do it in terms creating new radius tags. What I am doing involves creating html tables from a database and doing this with radius tags has a few problems:
- it is beyond my understanding of what radius tags are capable of. For example, how can I pass a radiant tag the id of a record to display, if the record does not correspond to a Radiant page? I don't want to create Radiant pages for every record. The documentation for the tagging engine isn't strong and I don't have the time available to figure out how to use it.
- what if I want to port my application to some other platform? It would still run on rails but would not necessarily use the radius tagging engine: frankly I am happy using erb/rhtml for my templating (the 'end users' won't need to fiddle with the presentation of this stuff).
So the question came to be: how can one write regular rails code with Radiant? How to bolt some regular rails Model/View/Controller code inside Radiant. How to use my existing Rails knowledge? I had to study the mailing list for a while but the answer was very straightforward:
- Install the share_layouts extension in your Radiant site.
- Create a new Radiant Extension of your own using the neat tutorial.
-
Create a regular controller in your extension using the syntax from the extension tutorial, i.e.:
script/generate extension_controller MyRailExtension myrails
-
Add the following code to your new controller so that it uses a radiant layout to render the page
radiant_layout 'Layout name' - That's it!
You then carry on developing your application with regular rails MVC code in the app/myrails directory of your extension. The command to add models/controller are in the extension tutorial. The code generators create the stubs for the standard Rails testing framework so I have been testing my Radiant extension by following the tutorial in my Rails Book. This was one of my reasons for choosing Rails in the first place, you can buy books about it.
Radiant is very easy to extend, both by defining new radius tags or simply writing rails code. This makes it potentially a very powerful platform. There is nothing to stop me writing the administration pages of my extension in the same way as regular Radiant extensions and coding the presentation part in plain rails. I want to do some AJAX and the querying of JSON snippets would be done through my rails controller, once I read that part of my book
Incidently, on the subject of Radiant development I once complained how slow radiant development was on my pc. This turns out to be because of the way I was connecting to a Mysql database over an ssh tunnel for every page access. I ought to use sqlite for development on the pc as connection would be instant (I don't want/need a mysql server running on my development pc).

