Build Joomla 1.5 MVC The Ruby on Rails Style
This articles explains the a ruby on rails plug-in I developed that utilizes some features of Ruby on Rails such as Plug-ins, Rake, Generators, Migration and ActiveRecord to speed up some development time for Joomla projects.
This is not a first time that someone used Ruby related tools for other projects than ruby. Capistrano, the web application deployment utility written in Ruby, has been used for Joomla sites deployments. You can read about it at http://www.adaruby.com/2007/08/14/deploying-joomla-using-capistrano-20/
Why I made this tool
I am a ruby on rails developer who has started developing in Joomla 1.5 Content Management System. Joomla 1.5 has a MVC-based architecture very similar to one in Ruby on Rails. It’s very clean and understandable. The only problem is that much of the setting up and packing procedures requires manual labor. It is possible to use ant to do some packaging but the level of automation acquired using ant is limited compared to rake (make in ruby) and in addition in ant you must write long XML scripts. Yak.Moreover Ruby On Rails comes with pre-packaged generating tools to create empty skeletons for controllers, models and views which can be used for Joomla projects with some modifications. In addition, it is possible to use Rails Migration class to create the install and uninstall SQL files. That means instead of writing syntax-error prone SQL statements, you can write them in plain ruby and it gets translated to SQL statements.Who can read this
I made the following assumptions about the your level of knowledge in Ruby on Rails and Joomla.
- You are a rails developers who has recently turned to Joomla 1.5
- You know how to set up a rails environment and make it work with MySQL
- You know the ruby scripting language and Rails and have good understanding about some rails tools and elements such as Plug-ins, Rake, Generators, Migration and ActiveRecord
- You know about Joomla 1.5 and know how to set it up with Apache, MySQL
- You have a good understanding about Joomla extensions like components, modules and plug-ins and you are familiar with new Joomla 1.5 MVC framework
Lets start
Download Joomla 1.5. and Install and set it up. Checkout the Joomla site for installation instruction.
Download rails and set it up. check out http://rubyonrails.org for instructions.
First lets create a rails project and call it joomrails. In shell we type
rails joomrails
This creates a rails project named joomrails. Then let’s install the joomrails plugin the googlecode repository
cd joomrails
./script/plugin install http://joomrails.googlecode.com/svn/trunk
The joomrails rails plugin gets installed. As the result some of the rails default directory like public, app gets removed. It’s okay since we are not working on a rails project. Now Lets create a Joomla Wrapper within our rails project.
./script/generate joomla /path/to/your/joomla/project

This creates three directories
japp -> soft link to your joomla project directory
jextensions -> holds your joomla extensions
jpkg -> hold the packaged extensions
Everything is set. Let’s create a component named web_realtor
./script/generate jcomponent web_realtor
this creates the following joomla component skeleton

As an example let’s create a controller for the admin site and name it property_manager.
./script/generate jcontroller admin web_realtor poperty_manager
This creates a component controller and view skeleton named property_manager with all the necessary files and folders

Same way you can create models. For example to create a property model we type
./script/generate jmodel admin property
Now lets build and package the component, we type
rake com:webrealtor:build
this builds and packages the components and places it in the pkg folder. This also iterates through the component folder and creates a manifest and places within webraltor.xml file which is the component install file.
There is more to joomrails than just generators. There is a use of ActiveRecord and Migration files to create SQL statements using the ruby languages instead of writing it in plain SQL. Ruby on Rails developers really appreciate this feature. The db folder within the component webrealtor, contains a file called 01_install.rb. The structure of the file is as follow

The method self.up is to create install.sql file and self.down will generate the uninstall.sql file. So lets create a table properties for our model property

Now if we build this component the install.rb will generate two files install.sql and uninstall.sql in the admin folder that will look like this.
install.sql file:
CREATE TABLE `#__properties` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `user_id` int(11) DEFAULT NULL, `name` varchar(255) DEFAULT NULL, `address` varchar(255) DEFAULT NULL) ENGINE=InnoDB;
uninstall.sql:
DROP TABLE `#__properties`;
Another feature that I added is a way to be able to continue developing on a component after installing it. The problem is that after a component is installed the source is copied to the joomla project directory under joomla/administrator/components/com_adminyourcomponent and joomla/components/com_siteyourcomponent folders. by typing rake com:componentname:link the installed component folders in the joomla project joomla/administrator/components/com_adminyourcomponent and joomla/components/com_siteyourcomponent are deleted and instead soft links to your component site and admin folders in the jextension directory are created. This allows us to use the existing project of our component to develop.
So in our example we type
rake com:webrealtor:link
This instruction ends here. Leave me a comment if you need some help using this. Or let me know if there are bugs which is for sure. I am hosting the project home page at goolge at joomrails.googlecode.com.
Flex / AIR / Rails / Joomla Get Together

Come and Drop by for a casual and friendly get-together.
We are arranging another AIR/Flex/Rails workshop event on Wednesday March 19th. We’ve invited a few people to discuss their insights working with these technologies. Peter Armstrong (http://peterarmstrong.com ) will join us and talk about his new released book “Flexible Rails” (http://flexiblerails.com ). Flexible Rails is the term Peter uses to describe the integration of Adobe Flex with Ruby on Rails as the back-end. Flex supports building powerful graphic user interfaces while Rails simplifies database integration. Peter is also having a full-day Rails/Flex workshop on March 31st. He’ll be talking about that as well.
Atul Nagpal, an AIR presenter in the last event, will be joining us again to talk about his fascination with Adobe AIR and Flex. He will be showing some of his application that he’s developed using AIR. Finally Rastin (www.rmdstudio.com ) and I will be doing a comparison between Ruby on Rails and the new MVC Architecture in the Joomla! 1.5 Content Management System framework.
This is a small get together not a classroom. You don’t have to be a Ruby, AIR or Joomla expert to enjoy this event. Our goals is to get together and learn something new in a friendly environment.
If you have made an application and would like to demonstrate to others, let us know we will post it on the blog and we can discuss it at the event.
We will be providing coffee and doughnuts and going to the Steamworks for a round of beer afterwards.
To attend click on the button below


