what is ruby on rails? - ruby-on-rails

I am a front end developer (HTML,CSS,JS & jQuery) I know a bit of PHP. I am trying to grasp what Ruby/Ruby on Rails is.
On http://rubyonrails.org/ it says "Ruby on Rails is an open-source web framework that's optimized for programmer happiness"
In actual, non-dreamy terms, what is special about Ruby/Ruby on Rails, and how can a person like myself benefit from learning to use it?
My simple question is: whose sister is it? PHP, mySQL, ASP, coldFusion, jsp, apache?
What does it do?

The Language
Ruby is a recent programming language that shares most of its heritage with Perl and Smalltalk. You can see what Ruby looks like (and try it yourself) at tryruby.org.
Just like you can use PHP to write web pages, you can do the same thing with Ruby.
The Framework
Ruby on Rails is a set of software devices that help you to more easily write a website in Ruby. The primary things they try to facilitate ("make easy") are:
Storing related data (e.g. blog posts and the comments on them) to a database.
Accepting web requests and respond to them programmatically (e.g. check a user's password)
Composing HTML using your data, with layouts and templates to make it easier.
"Rails," as it's called for short, is built with extreme prejudice towards certain application models, particularly MVC. What this means is that unlike PHP, where any .php source file is fair game for any bit of code, most code in a Rails application is written in a particular, conventional place. When people compare Rails to PHP, they often point this out.
There's a lot I didn't cover, but these are Rails' most basic features. To see what it looks like, I'd suggest watching the infamous, "Creating a Weblog..." screencast.

If you're looking for something to compare it to for someone coming from PHP, think of it like CakePHP for ruby. It's a bunch of pre-developed low-level classes and systems that can then be extended out to use in many different systems. It also bundles in a lot of other helpful tools and a plugin architecture. It uses ruby and an HTML templating language based on ruby (erb) rather than PHP.

It's a framework for Ruby whose sweet spot is CRUD based web apps. They make a number of assumptions (aka "conventions") that make it easy and fast to create tables with 1:1, 1:m, and m:n relationships, objects, controllers, and web pages for exposing and manipulating that data on the web.
Ruby is just another object-oriented language, like Java, C++, or C#. It was invented by a gentleman from Japan.

This might not be the best analogy, but like you would use HTML/CSS/JS to display a cohesive entity with specific stuff in their specific places. Rails provides a framework to allow you to work in an organized environment with specific stuff in their specific places. As well as having goodies to provide for more rapid development.
Generally:
Html would contain the content you want to display, while CSS would help control the specific look of that content, while JS would allow you to manipulate or interacte with said content.
Rails, uses MVC (Model, View, Controller) to provide a similar organization. Where Data objects are generally categorized as Models, while Views control the displaying of the Data. And Controllers would would facilitate the flow of that data from View to Model and vice versa.
Rails is not the only game in town. So do look around, as there are other great frameworks out there, and find the one best suited to your style and language needs.

Philosophy and design
Ruby on Rails is intended to emphasize Convention over Configuration (CoC), and the rapid development principle of Don't Repeat Yourself (DRY).
"Convention over Configuration" means a developer only needs to specify unconventional aspects of the application. For example, if there is a class Sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table "products sold", that the developer needs to write code regarding these names. Generally, this leads to less code and less repetition.
"Don't repeat yourself" means that information is located in a single, unambiguous place. For example, using the ActiveRecord module of Rails, the developer does not need to specify database column names in class definitions. Instead, Ruby on Rails can retrieve this information from the database based on the class name.
Taken from wikipedia

Ruby An elegant object-oriented programming language with objects like Smalltalk and syntax something like Python and Perl. It's kind of what PHP would have been had it been done right. That is, Ruby takes features from advanced "real" languages and combines them with the interpreted efficient syntax and library-rich practicality of Perl, Python, and PHP.
RailsAn advanced web framework. Many recent web frameworks are considered to be copies of or at least inspired by Rails. (Google "rails clone".) "The first good web framework".
Both Ruby and Rails are generally highly regarded.

Ruby is an object oriented programming language. Rails is a framework built in Ruby for developing web applications. I have been using rails for about 6 months now, and its been great so far. If you want some of the same features of rails, you should also consider django (python), cakephp or symfony (php).
Pros:
MVC Architecture - Code is organized,
broken up into small, manageable
files
Database abstraction - you dont have
to write SQL queries, database types
are easily interchanged
Convention over Configuration - rails automatically knows file, database, variable names without explicitly being specified
Fast Development - Rails requires less lines of code because of all the functions it automatically takes care of and is more expressive, resulting in faster development
Cons:
Slower - this is often debated, but a comparable rails application is slower than its PHP counterpart. Rails 3 is supposedly going to include speed increases.
Less Literature - rails lacks the plethora of tutorials, books and api that is available for PHP.
Less Hosting Support - Not all shared hosts support rails, but you can set it up on any vps or dedicated. Deployment is also a bit tougher in Rails as opposed to PHP

Ruby is a programming language. Ruby on Rails is a piece of software written in Ruby, it helps you develop web applications.
You can look at Ruby on Rails as if it is a set of tools. It helps you do common tasks when you're making a dynamic web application. E.g. session handling, cookies, database interaction, etc.
Rails goes beyond being just a library, though. To really understand this, you would have to experiment with it, which is actually very easy.
Rails Guides is a fantastic place to start.

Related

Rails or Sinatra as a web framework for a NoSQL and DDD project?

I am evaluating Rails as a framework for a new web project. My only concern is that as far as I know, Rails was built with a very strong inclination towards CRUD and SQL applications.
The architecture style of my application will be domain driven with a NoSQL database, almost the opposite to the roots of Rails. I also have the impression that Rails apps are strongly tied to one single database.
I have seen some work trying to make Rails NoSQL-friendly, specially DataMapper 2 seems very interesting (and taking a long time), but I am wondering if the current Rails architecture is suitable for DDD projects (anti active record).
Ideally I would like to use Rails for its maturity, community and Ruby. But I have also seen many mature projects that had problems to embrace new programming styles which were not considered from the beginning.
Also I am considering a micro-framework like Sinatra which should give me the flexibility to use my own architecture style. The only downside of that I would prefer a framework taking care of as many things as possible (no long experience with web development).
It sounds like Sinatra is your best bet.
Some of the concepts you've described are not, traditionally, out-of-the-box so to speak for a Rails application - and configuring multiple NoSQL databases with datamapper will give you some headaches.
With Sinatra, you get the best of both worlds. It's a domain specific language, not a framework - so you can customize it exactly the way you need it. Whilst it will take some work to setup, having complete control over the framework your application uses is very satisfying. Build it from the ground up.
Rails or Sinatra?
Datamapper for Sinatra (can be easily adapted to use NoSQL)
Check out an example MVC I built with Sinatra
Don't get me wrong, I love Rails, but the moment I have to start playing around with it's internals, you're better off just building it yourself with Sinatra.

Uses of Ruby on Rails

I am a somewhat experienced rubyist, but I am now starting to do rails development. I know rails is used to make "web applications" but what exactly does that mean? Do you build entire sites with rails or do you build a feature for a website in rails, and integrate it in to an existing website? (I know this question is kind of vague, but any answers to how ROR is used in the creation of websites would be much appreciated).
Generally speaking, you will build a full site with Rails, though you can integrate it into an existing website, as well. It is designed to provide a top-to-bottom solution for entire websites.
For standalone features or small scripts you just want to expose to the web, you might look at something like Sinatra or Camping.
What is Ruby on Rails?
I'm also build some rails applications in that I had entirely use rails to develop my web application. It's quite easy rather than using two or three languages. But when I developed I had to use Javascripts, CSS and Ajax to create more attractively
For me it's a great framework to build website and minimal knowledge is required although experience and knowledge of ruby gives you an upper hand.
I also feel that rails is good not only to build websites but to manage it.
Also the support community of rails is awesome and is complemented by guys like Ryan bates with their screen casts.
Also when we build a website using ror, we have the flexibility to concentrate on different features at different times or by different person.
This gets a great modular structure.
So you can design the basic functionality today and tell your colleague to get the views attractive using JS and friends without affecting your functionality.
Also the external support for rails (like gems and plug ins) is awesome and makes life heaven!
I would suggest that it's a great framework and the best feature is that it is a very easy to begin and learn but it always surprises you with new things.
Thus it allows you to learn a lot!
Hope it helps.
The website/web application distinction is made because there are many Rails apps in existence with no front end or 'website' to speak of. Using Rails, one could serve JSON amongst a cluster of compute nodes for data aggregation, or text to unix sockets for display on terminals. The uses for Rails are only limited by ones imagination, and you could even use Rails for single host interprocess communication if you desired. This might prove effective for a highly skilled rails programmer rather than learn a new tool to achieve similar results.

Is the Rails ecosystem a suitable replacement for drupal

I want to make a community based site, which is Drupal's strength. However I also want to try other frameworks, especially Rails.
One of the best things about drupal is its huge modules library. If I were to switch to Rails, would I be able to find similar functionality freely available as plugins, or would I have to rebuild?
Does Rails have the equivalent of (as plugins or gems):
CCK/Fields?
Node Reference?
Views / Views Relationships?
PathAuto?
Threaded Commenting?
Multisite Functionality?
Apache Solr (or equivalent) Integration?
Thanks.
I'm afraid you'll probably hear this answer a lot, but it's not a suitable comparison.
Drupal is a ultimately a CMS, Rails is a framework. Apples to oranges, or perhaps even Apple Juice to oranges. Out of the box, you fire up Drupal and it does 'things': it has a database structure, the concept of nodes, interfaces blah, blah. If you fire up Rails you have an empty project.
As far as I know there isn't a "Drupal-on-Rails" project that would be a suitable equivalent. However, I can attest to the fact that there is an awful lot of Ruby/Rails community and O/S work out there and you might find something suitable. I'd also say that the level of modularity in Ruby and Rails tends to mean that the range of plugins/modules/gems one can use is much greater.
My personal $0.02. If Drupal does what you need, just use Drupal: it's mature and has a great community. It's never a good idea to try to port Project X over to a new language as a learning exercise because you'll inevitable fall into the "Well that's how it's done in language X!" trap and become disenchanted with the new system.
If you're wanting to learn Rails (which you should, it's awesome) I'd suggest you'd be best working on a small project and seeing what the ecosystem offers before deciding if it's suitable for the needs of your bigger projects.
I have to second what Govan said, but add to it.
With Drupal, unless you really want to get into building your own modules and extensions you are really interacting with an application. Even when you start using CCK, all you are really doing is flipping switches, filling in forms and defining new options for content on the site.
Ruby on Rails is two things, and neither of them bares much similarity to Drupal. You asked "How hard is it really?". To answer that you need to understand what both Ruby and Rails are. Ruby is a programming language designed to make the life of the object purist programmer simpler and more pleasant. So, the first part of how hard is it is simply to answer "how long do you feel it would take you to learn a completely new programming language, like PHP but different".
Rails is an 'opinionated' framework. It's opinionated in that it lays out how a Ruby web project should be structured, as well as providing multiple APIs for everything from database access to web presentation. To answer the "how hard is it" question for Rails then (assuming you know Ruby by this point), you have to answer how much do you need to learn about cacheing, database design, page design, RESTful programming etc etc.
It's not a short journey. you asked if there is an equivalent to CCK for Ruby and Rails which implies to me that at this point your knowledge of programming is somewhat limited. Ruby and Rails interact with the database. CCK lets you define things in a database. Thus, with Ruby and Rails you are effectively bypassing the wonderful dialogs and forms that CCK provides you with and doing the data definition bits yourself, by hand, in code.
From experience, when I've hired experts in another programming language and framework into my Rails teams, it has taken them between 1 and 3 months to get productive, and a further 3 to 6 months for their productivity to start to raise and approach that of the Rails experts on my team.
Thus, in your particular case, I would not recommend a switch away from Drupal to Ruby on Rails.
Drupal (core) on ohloh (130k lines of code) is estimated to be 34 years of work worth.
Drupal (contributions) on ohloh (modules for Drupal 4-6 (7M lines of code)) is estimated to be 2113 years of work.
That is the power of a community, and that is something that you can never replicate. I remeber there was a guy, who tried to port Drupal to python calling it drupy, but that project died before something useful ever came out of it. Even if you copy the code, you can never copy the community.
The thing you need to realize, is that each community is different. So even if you find a project that can solve your code needs in a RoR or a different language/framework, it will never be like Drupal and vice versa.
So don't try to find a replacement for Drupal, but go explore and try new things. You might end up learning new things, that you can use for your Drupal projects.
I've read this times and times again that people saying comparing drupal an ror is comparing apple to orange which is wrong.
I think the saying itself BS. Yes we want to compare apple to orange and find out which is better. We even want to compare apple to steak. Said that, they are different. Yes, we all know. I have limited experience with either. I first thought Drupal was great and can help me build the website I wanted overnight (or over a week or month) then it didn't happen (not blaming Drupal).
My impression is that, Drupal maybe still great but it has a learning curve and needs a lot of other knowledge or talents to use it well and tweak it. RoR on the other hand is a more general framework and needs programming (Drupal needs too actually).
If you are more of a web designer person with a little PHP maybe Drupal is better fit.
If you are more of a web developer type don't want to spend time looking for modules and make them work but rather do them yourself (not really from ground up) then maybe RoR is for you (with the same amount of learning). So yes they are both good for different purpose, background, etc.
For now I will go with RoR (or dJango and other ORANGEs). My 2 cents.
Rails, since version 3.0, has officially adopted the once-controversial engine way of incorporating third-party apps. this is roughly the equivalent of Drupal's modules/plug-ins, from a 10k foot perspective. To build a community-based site, you could make use of an engine called, appropriately enough, "Community Engine." http://communityengine.org/features.html"
The Rails ecosystem doesn't have anywhere near the same number of modules Drupalists have available to them, but there are enough good quality ones to cover the chief basics.
Drupal has so many strong areas, its hard for just one or two people to recreate it in a decent amount of time with any language. PHP, Ruby, Python, etc.
You have the core node system, taxonomy, aliasing, menus, users, permissions, and modules, the database api, and form api, among others.
You'd have to know how to assemble all these pieces independently and create the structure necessary for it to all work together.
It would take more than 'a few hours'. I would say, even if you are a ROR master, you're looking at a year to two years of solid consistent work to get the best parts of Drupal for a new system.

Rails and CodeIgniter

I'm currently studying Ubuntu Server administration, and also HTML/CSS. When it comes to the application logic I can see huge advantages in using a reputable CMS like Drupal or Joomla. I find though that both of these are implemented in PHP. I wish to study Rails as Ruby makes a nice switch from the ubiquitous C-style syntax. With PHP dominating the majority of web applications released in the last few years; should I just bite the bullet and learn it along with CodeIgniter, or should I go with Ruby on Rails and work with one of the smaller compatible Rails CMSs out there?
There's no reason to choose one over the other when you can learn both.
You might have to pick one now, and the one you pick should provide the most value for you in the least amount of time (for example, if most of your jobs are in PHP, continue to focus on getting better in PHP and PHP-based systems). However, if you have time, you should continually learn new languages, techniques, and paradigms - it will only make you a better developer.
If you are more or less an experienced programmer, go with Rails and learn something new and different, even more if you plan to re-use your code as a freelancer. Also take a look at HAML and SASS (yes, HTML and CSS are ancient and outdated as PHP)

Common usage of Rails applications?

What are the most common tasks for Rails applications? I mean, for example, for small and simple sites people usually choose PHP, because it's really easy to maintain and to deploy, most hosting platforms support all your needs. But I'm interested what people usually produce with Rails. What kind of applications?
Pretty much the deal is, if your app would benefit from object-oriented design, Rails would do well. If your app would not benefit from object-oriented design, Rails would not.
The framework revolves around a relational object model, storing items in a database (e.g. posts belong to users). For large apps that have that sort of structure, Rails makes the development process easy (relatively). Running anything else with Rails, though, would be far too much overhead to be worthwhile.
So, say you have a one-function website, e.g. take input and encrypt to MD5, SHA-1, and other forms of encryption. Using Rails would be pointless. You can still use other Ruby-based frameworks if you just like Ruby, but Rails would not be the right choice - and I'd probably recommend PHP, since it does well at simple scripts.
You should check out Ruby on Rails: Applications.
Mostly large applications, that benefit from the MVC pattern, and don't get drowned by the overhead of such a large framework.
www.basecamphq.com and www.github.com are good examples.
With the advent of phusion passenger I think using rails can be warranted in almost every case if you like developing with it. The deployment overhead has gotten very small and the development overhead does not exists if you are used to the framework.
Check out 37Signals who has developed Rails and use it in their products.
It sounds like you're asking "what framework/language should I use to make a website?" There's no one perfect answer to that, as a good answer will depend heavily on your knowledge, experience, place of employment, and the audience for which the site is designed.
That being said, Ruby on Rails is a good choice, and there are several benefits to using it:
it has a large base of users, so that your questions can be answered on sites like StackOverflow.
it's being actively developed, and there are many tools for it that are designed to help you be productive.
it simplifies interactions between your web site and your database using an object model.
it allows you to easily describe the dependencies between various aspects of your application.
it's not PHP. :)

Resources