What Is Ruby on Rails

what is ruby on rails?

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:

  1. Storing related data (e.g. blog posts and the comments on them) to a database.
  2. Accepting web requests and respond to them programmatically (e.g. check a user's password)
  3. 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.

In Ruby/Rails, what is Rails?

Ruby is a language, much more closely related to Perl or Python than to a C-based language like Java. Ruby is very approachable as a language, and there's even an interactive console that you can use to quickly experiment with. Ruby itself is interpreted, so you have a lot of dynamic capabilities at your disposal. It's really a good language that you can pick up quickly.

As you say, Rails is a MVC framework that includes an ORM (ActiveRecord), a view template engine (ERB), and a variety of extensions to the standard Ruby library. Most Rails applications are websites, but you can use Rails for other purposes, such as an API-based headless server or a mobile application server - these are often combined together to make full-stack applications.

I typically recommend 2 books to programmers looking to make the switch:

  • Programming Ruby by Dave Thomas, Chad Fowler, and Andy Hunt
  • Agile Web Development by Sam Ruby, Dave Thomas, and David Heinemeier Hansson

"Programming Ruby" covers the language constructs and use of standard tools with decent examples in the first half of the book, followed by a standard library reference in the second half. It's well written, and loved by millions as 'The Pickaxe Book'. Make sure to get the Ruby 1.9 & 2.0 book, as this covers the most recent Ruby versions and features.

"Agile Web Development" covers the introduction to Rails by developing projects and explaining the problems and decisions made along the way. I've found this to be very helpful as an introductory book for programmers looking to make the switch from another language/framework.

What is the difference between Ruby and Ruby on Rails?

Ruby is a programming language. Ruby on Rails ("RoR") is a web-application framework that is implemented in Ruby.

So they not only "work together" but RoR depends on Ruby.

What does it mean for a programming language to be on rails?

To address your confusion with the metaphor (though it has been answered in other words under your question):

Groovy is to Grails as Ruby is to Ruby on Rails, but what does that mean?

Grails was a web framework built on/with the Groovy programming language to do the same thing for Groovy that Rails (a web framework for Ruby) does for Ruby.


What does it mean to be "on rails"?

The answer to this comes down to the essence of these web frameworks.

These web frameworks (Grails & Rails) are built on the premise of "convention over configuration", which means that using common conventions to develop web applications can lead to higher productivity and more maintainable applications (this is a gross generalization). And by defining a convention and sticking to that you will find that your applications are easy to generate and quick to get up and running.

This is what it means to me to be "on rails", just like a train. When a new train route is developed there is no worry about reinventing the way the train will get from one place to another, it's been solved by a single convention for decades: rails. Just as the tracks on a train route constrain its path from two locations, convention-based web frameworks use conventions to the flexibility of application developers so that they can concentrate on what the essential business problem of their application.

One key benefit of a convention for a web framework is that the web framework can now make assumptions on how certain layers of the application hook together. In Rails, one can usually assume that if one's database table has a plural name, the ActiveRecord class mapped to that table will have the corresponding singular name. Consequently, Rails code generators can consume the data-mapping information to generate data access code such as dynamic finders, migrations, lazy-loaded association traversals, etc. This data access code in a configuration-based framework is laborious to code by hand.

@ variables in Ruby on Rails

title is a local variable. They only exists within its scope (current block)

@title is an instance variable - and is available to all methods within the class.

You can read more here:
http://strugglingwithruby.blogspot.dk/2010/03/variables.html

In Ruby on Rails - declaring your variables in your controller as instance variables (@title) makes them available to your view.

what is ruby used for BESIDES rails?

Firstly, PHP was built to be a server language, first and foremost. That's one of the primary reasons it's not usually used for anything other than web applications - it's not designed for it and therefore can't match up to the requirements of, say, a scripted desktop application.

Ruby was designed as a general-purpose scripting language, and thus has a wide support for a number of different applications. It has been used across the board for everything from web applications, to web servers themselves, to intelligent graphing libraries, to picture recognition engines, to threaded database servers, to low-level system utilities. It has a wide spectrum of use throughout computing.

Rails has most certainly boosted the popularity of Ruby by a huge amount, brought it up into the forefront of scripting languages, spawning 40+ books, 18 conferences, distribution with nearly all the major operating systems and 7 different implementations to boot!

To begin with, all of Rails' internals are written in Ruby itself, but all of the Rubygems, libraries, snippets or anything else that is used by Rails developers is written in Ruby too, and is most likely built to work outside of the Rails stack.

Having said that, the popular web framework is not the reason why Ruby is popular. Sure, it has helped bring much-needed attention to the language, but it's not the reason why people use it day to day. It's used for everything from web applications to desktop GUI applications because of it's simple, elegant syntax, it's clean, sensible and complete standard library, it's wide ecosystem of community code, support and toolchains.

Ruby is used because it rocks.

Learning Ruby on Rails

I've been moving from C# in my professional career to looking at Ruby and RoR in my personal life, and I've found linux to be slightly more appealing personally for development. Particularly now that I've started using git, the implementation is cleaner on linux.

Currently I'm dual booting and getting closer to running Ubuntu full time. I'm using gedit with various plugins for the development environment. And as of late 2010, I'm making the push to use Vim for development, even over Textmate on OS X.

A large amount of the Rails developers are using (gasp) Macs, which has actually got me thinking in that direction.

Although I haven't tried it, Ruby in Steel gives you a Ruby IDE inside the Visual Studio world, and IronRuby is the .NET flavor of Ruby, if you're interested.

As far as books are concerned, the Programming Ruby (also known as the Pickaxe) book from the Pragmatic Programmers is the de-facto for learning Ruby. I bit the bullet and purchased that book and Agile Web Development with Rails; both books have been excellent.

Peepcode screencasts and PDF books have also been great for getting started; at $9 per screencast it's hard to go wrong. I actually bought a 5-pack.

Also check out the following:

  • Official Rails Guides
  • Railscasts
  • railsapi.com or Ruby on Rails - APIdock
  • The Ruby Show
  • Rails for Zombies
  • Softies on Rails - Ruby on Rails for .NET Developers
  • Rails Podcast
  • Rails Best Practices

I've burned through the backlog of Rails and Rails Envy podcasts in the past month and they have provided wonderful insight into lots of topics, even regarding software development in general.

What about Ruby On Rails(RoR) JSON and MySQL for Backend?

It's better to choose a database backend if you are going to build a Rails application. If the data should be structured in JSON, you may choose Mongodb which is very popular solution for noSQL backend. If the game is designed with traditional structure, MySQL and Postgresql are all very good choices supporting your business. ActiveRecord is core of Rails and has well designed APIs and many many powerful methods and helpers that could make your development easy. So using SQL backend DB is a good option.



Related Topics



Leave a reply



Submit