Ruby on Rails development took place because of individuals needing a database backed web program that doesn’t have any obligation to an operating system. Ruby Rails also has a wide range of web servers and databases. With Ruby Rails, it was developed to operate with any operating system to build applications that are database backed.
This open source web development framework, which has literally taken the web application world by storm. This is a complete infrastructure that allows for the development of web applications in real time. Its popularity is growing and is proving to be a threat to Java and .Net. when it comes to application development.
Advantages
Ruby on Rails development took place in 2004 and a number of advantages do exist with this type of technology. Here are some of the advantages:
* Ruby on Rails supports MySQL, Postgresql, Oracle, and a variety of others.
* Developers are able to received detailed error logs in order to debug applications.
* Users have the ability to develop URLs and dynamic websites that are search engine friendly.
* Its model view architecture allows a separation between data and logic.
* There are so many libraries that the coding of common programming languages has been simplified.
It is all of these advantages that have made Ruby on Rails a very popular framework. It allows for rapid application development, so that means that there is no more having to wait for long periods of time for an application to be built.
Who has enjoyed Ruby on Rails Development?
There are many sites that have enjoyed Ruby on Rails development? Social networking sites, community sharing sites, blogs, and many more sites have taken advantage of Ruby on Rails. This is why there has been a steep rise in demand. The newest version of Ruby on Rails that was developed in 2008 is 2.0, which enables the development of web 2.0 applications. It is superior to programming languages, such as PHP, ASP, and Java. Ruby Rails development ensured that it would be more advanced than .NET and Java.
Many companies, particularly those that are outsourced to use the power of Ruby Rails to develop websites that are database driven, are finding a lot of success with Ruby Rails. They are able to create applications that benefit their clients greatly. They basically leverage the power of Ruby Rails by combining rails framework with Ruby programming. Even PHP programmers have been successful in developing scalable and robust applications that are very affordable. This also enables these companies to have fast turnaround times because applications are so quick to create.
Being that we live in a world that wants everything done immediately, it only makes sense that Ruby Rails development took place in the first place. It is making the technological world operate a little bit faster than what it used to and everyone is loving it. Eventually, Ruby Rails development will lead to even more advanced technologies that are even faster and better than ever.
VN:F [1.0.9_379]
Rating: 5.0/5 (1 vote cast)
This article tries to demonstrate that Java can be more productive than Ruby. We are going to develop the same application of the article Rolling with Ruby on Rails Revisited (part 1 and part 2) but using POJOs annotated with JPA and a Model Driven Framework, OpenXava in this case. The result is that with less code, and less time you obtain a more powerful application.
Ruby and rails: The regressive framework
Ruby on rails is so elegant, so easy, so productive. I cannot avoid read and heard continuously these comments. For example, the article Rolling with Ruby on Rails Revisited of Bill Walton says:
“What would you think if I told you that you can develop a web application at least ten times faster with Rails than you can with a typical Java framework?”
Oops! Ten times faster!
Well, after these comments I decided to learn Ruby on Rails. I need to know the true key of the productivity and programmer happiness.
After have a taste of RnR I found it a very classic framework, with old techniques:
- Ruby is a dynamically typed language, as Smalltalk. I prefer statically typed languages.
- Scaffolding is passive code generation, as IDE wizards or AppFuse. I prefer active code generation, or even better, no code generation at all.
- Relational database centric: the code generators and ActiveRecord promote think first in tables after in classes. I prefer a more pure OO, as Hibernate, JPA or even ODBMS.
- MVC: I’m looking for something newer and better that an old MVC framework.
The Java problem: Java developers
The productivity in Java world is a cultural problem, not a technical one. That is this is not a Java fault, it’s our fault, we, the Java developers, need to design very beautiful architectures, to apply everywhere the GoF patterns, to do everything reusable, to put 3 tiers in all our systems and to use web services for all. We are not looking for simplicity, therefore we have not found it. But, Java is a very elegant language that allows simpler approach to software development.
Java productivity: The other way
A way for productivity is to use a Model Driven approach. That is, develop the model part, and only the model part, of our application, and to use a framework to produce all the application from it. MDA, OpenXava, Trails, NakedObjects, RomaFramework and JMatter are examples of this approach.
The goal
This is the main screen of the wanted application:

Basically, the app’s supposed to do three things:
- Display a list of all recipes.
- Create new recipes and edit existing recipes.
- Assign a recipe to a category (like “dessert” or “soup”).
The Ruby on Rails first sprint
The first step using RnR is creating the new project, from command line you have to write:
$ rails cookbook2
Now you must create and configure your database.
Then it’s the time for writing your first code, in this case SQL code:
01.drop table if exists recipes;
02.drop table if exists categories;
03.create table categories (
04. id int not null auto_increment,
05. name varchar(100) not null default '',
06. primary key(id)
07.) engine=InnoDB;
08.
09.create table recipes (
10. id int not null auto_increment,
11. category_id int not null,
12. title varchar(100) not null default '',
13. description varchar(255) null,
14. date date null,
15. instructions text null,
16. constraint fk_recipes_categories foreign key (category_id) references categories(id),
17. primary key(id)
18.) engine=InnoDB;
Obviously you have to execute these sentences against your database.
And the final step is generate the Ruby code, you only need execute the next command in the shell of your O.S:
$ ruby script\generate scaffold recipe recipe
$ ruby script\generate scaffold category category
Yes. You have the very first version of your RnR application ready to run.
Yes, very little work, a simple “create table”, and executing a wizard. Let’s see the result.
The Rails result
This is the resulting application:



Little work. Little result.
The JPA on OX first sprint
Go on using OpenXava. The first step using OpenXava is creating the new project:
$ ant CreateNewProject.xml -Dproject=CookBook
Now you must create and configure your database.
Then it’s the time for writing your first code, in this case Java code:
Recipe.java:
01.package org.openxava.cookbook.model;
02.
03.import java.util.*;
04.import javax.persistence.*;
05.import org.openxava.annotations.*;
06.
07.@Entity
08.@View(members="title; description; date; instructions")
09.public class Recipe {
10.
11.@Id @GeneratedValue @Hidden
12. private Integer id;
13.
14. @Required @Column(length=100)
15. private String title;
16.
17. @Column(length=255)
18. private String description;
19.
20. private Date date;
21.
22. @Stereotype("HTML_TEXT")
23. private String instructions;
24.
25. public Integer getId() {
26. return id;
27. }
28.
29. public void setId(Integer id) {
30. this.id = id;
31. }
32.
33. public String getTitle() {
34. return title;
35. }
36.
37. public void setTitle(String title) {
38. this.title = title;
39. }
40.
41. public String getDescription() {
42. return description;
43. }
44.
45. public void setDescription(String description) {
46. this.description = description;
47. }
48.
49. public Date getDate() {
50. return date;
51. }
52.
53. public void setDate(Date date) {
54. this.date = date;
55. }
56.
57. public String getInstructions() {
58. return instructions;
59. }
60.
61. public void setInstructions(String instructions) {
62. this.instructions = instructions;
63. }
64.
65.}
Category.java:
01.package org.openxava.cookbook.model;
02.
03.import java.util.*;
04.
05.import javax.persistence.*;
06.
07.import org.openxava.annotations.*;
08.
09.@Entity
10.public class Category {
11.
12. @Id @GeneratedValue @Hidden
13. private Integer id;
14.
15. @Required @Column(length=100)
16. private String name;
17.
18. public Integer getId() {
19. return id;
20. }
21.
22. public void setId(Integer id) {
23. this.id = id;
24. }
25.
26. public String getName() {
27. return name;
28. }
29.
30. public void setName(String name) {
31. this.name = name;
32. }
33.
34.}
And the final step is to generate the dababase schema, you only need to execute the next ant target from your project:
$ ant updateSchema
Yes. You have the very first version of your OpenXava application ready to run.
Yes, very little work, a simple POJOs, and executing ‘updateSchema’. Let’s see the result.
The OpenXava result
This is the resulting application:


Note that the user can create,update, delete, generate PDF from list, export the list to excel, order by each column, paging with support for large resultsets and filter data. Moreover you can deploy directly, with no code, only executing an ant target, your application in a JSR-168 portal, and the look & feel of the OpenXava portlet adapts to the look & feel of the portal.
This is, from first time, an application ready for production.
Little work, polished result.
From a philosophical point of view the difference here between RnR and OX is that in RnR you write first the tables and in OpenXava you write first the classes.
The controllers
Rails has generated for you the controller logic for the basic CRUD, you can see it here:

In the other hand OX has not generated any code for CRUD, OpenXava just have a generic code for doing CRUD and Printing, and it is assigned automatically to all entities. You can write your own generic CRUD logic, or you can write a specific logic for a particular entity, but you haven’t a controller code for each entity. In this way, you have less code to maintain, and you can change the logic of all CRUD modules touching in a single place.
That is for controllers Rails uses generated code while OX uses generic code.
You can learn more about OX controllers in OpenXava wiki.
Adding a relationship
For adding a relationship from category to recipe in Ruby you have to write the next code in category.rb:

and this one in recipe.rb:

Yes, pretty simple. But, you have more work to do. You must edit cookbook2\app\views\recipe\_form.rhtml and add the next code:
1.<p><label
2.for="recipe_category_id">Category</label>
3.
4.<%= select("recipe", "category_id", Category.find(:all).collect
5.{|c| [c.name, c.id] }) %></p>
The result is:

For its part, in OpenXava you have to define the relationship using JPA in Category.java:
1.@ManyToOne(optional=false) @DescriptionsList
2.private Category category;
and in Recipe.java:
1.@OneToMany(mappedBy="category")
2.private Collection<Recipe> recipes;
And you do not need to touch any HTML-like code. You application will show just this:

You have a link for modifying or creating new categories from here.
Without adding any additional code if the user go to the Category module he will obtain a collection of Recipes in each Category, as following:

In this point the RnR application still does not have this features, you need to write some Ruby and HTML to code to obtain the same effect.
The main difference here between RnR and OX here is that in OX you do not write any HTML-like code, indeed you do not write User Interface code at all.
Calculating a initial value
The next step in the Ruby on Rails tutorial is to generated a initial value for a property. In RnR you have to edit the controller code in order to achieve it. Let’s see it:
You modify the new and update method adding the line:
1.@recipe.date = Time.now
The equivalent in OX is adding the @DefaultValueCalculator annotation in model:
1.@DefaultValueCalculator(CurrentDateCalculator.class)
2.private Date date;
You obtain the same effect in a more declarative way.
That, while in RnR you put the code on controller, in OX the code for calculating initial values, for validations and for business logic in general is on the model. OX promotes moving business logic from controller to model.
As curiosity, in the RnR article says: “I modified the model files so I need to restart our web server.” While using Eclipse WTP I only need to press Ctrl – B, and click on refresh in my browser in order to see the change of my model in my OpenXava application.
Conclusion
The main difference between Ruby on Rails and OpenXava is that RnR is a MVC framework, you have to write the model, the view and the controllers, and OX is a model-driven framework, you only need to write the model. The result is less code for a better application.
Another big difference is that RnR uses passive code generation; that is, it generates the code for you, but after it if you want to extend or refine the code you have to edit the generated code. OpenXava does not use code generation, the only code you have is the code you write.
You can find productivity inside the Java universe.
References
To learn more:
VN:F [1.0.9_379]
Rating: 3.0/5 (2 votes cast)