Ruby on Rails Fundamentals

A Dice Talent Community

Ruby on Rails locomotiveRuby on Rails is a full-stack, open-source Web framework used for writing real-world applications with more simplicity and less code than most XML frameworks. As the official RoR web site says, it’s “an open-source web framework that’s optimized for programmer happiness and sustainable productivity. It lets you write beautiful code by favoring convention over configuration.”

The happiness comes from Rails’s sustainable and productive approach to Web development. In 2005, when Rails was introduced, available frameworks were complicated to setup and developed mostly in Java and PHP. It left developers frustrated when it came to starting new projects—they had to begin from scratch in Java, setup a lot of XML files, and create several lines of code just to get a simple, “Hello World!” You had to know Struts, JSP, XML, Tomcat and more before you could get a Web project going. So based on that, one all-important thing was implemented on Rails and ported to several other frameworks: convention over configuration.

Rails app directoryThat’s a simple thing, unfortunately we, the developers, tend to make things complicated and create applications that you can configure in any number of ways. To streamline things, the core developers of Rails focused on convention and configuration only in the framework’s real guts. For example, all the controllers are called by a name and a single suffix: “_controller.” The names of database are referred to in plural (“products,” not “product” or “prod.”) It helps developers find what they’re looking for, quickly.

So, What Is Ruby?

Ruby was designed to focus on simplicity and productivity, and Rails takes advantage of these traits. In this environment, the concept of “DRY” —Don’t Repeat Yourself—is important, and Ruby provides a lot clever of ways to avoid code repetition. So, developers can do more with less. It needs more CPU power, but in this age of cheaper and cheaper hardware, that’s not much of an issue.

Behind the curtains, Ruby on Rails is a Model View Controller framework, with a pattern that’s among the most useful when developing Web applications. The framework’s main components are ActionPack, ActiveSupport, ActiveModel, ActiveRecord, ActiveResource, and ActionMailer. Essentially, Rails is a framework composed of other frameworks than can be used independently. Some details:

  • Action Pack: Handles requests and responses. This framework is part of Rails’s Model View Controller pattern, which serves the Web request, handling, routing, and view generation. To provide the response, it defines controllers that implement actions in order to render views.
  • Active Model: Provide the interfaces for the Model part of Model View Controller. This component is new in Rails 3.0. In previous versions, the model layer was based on ActiveRecord. In the current version, you can use any ruby class as a Model. This is very important because you can use your own persistence layer and glue it into Rails.
  • Active Record: This is the Object Relational Mapping (ORM) component of Rails, with a very nice zero-configuration feature. Naming and convention is the key to maintaining simple and minimal code to define classes that will be persisted in the database tables.
  • Active Support: a collection of utility classes and standard library of extensions that are useful in Rails. We can find this extensions useful for several Ruby projects.
  • Active Resource: Connects business objects and Representational State Transfer (REST) Web services. With ActiveResource, you can easily use REST to expose your ActiveRecord models with just a small amount of code. This is a useful way to create an API without much effort.
  • Action Mailer: This framework provides the email service layer, helping out to send the forgot password emails, registration emails, invoices for billing, etc. This class wraps ActionController from ActionPack to render the emails as page views, with the same render and templates like pages.

Rails control panel

Highlighted Features

  • ORM Embedded: no configuration needed.
  • Generators: for Controllers, Models, Views, Tests and other code that you’ll need. With just a command, you can have the whole CRUD (create, read, update, delete) working in your browser.
  • Migrations: With ActiveRecord, the DB structure is versioned. Migrations let you go backward and forward so the app can take care of any changes on the database structure.
  • Rack/Metal and Middleware: For speed, Rails provide access to the low level HTTP request/response handling, resulting in faster API access for example when rendering isn’t required. The Middleware uses the Rack interface to receive its request directly and sends the response directly to the front end. Middleware can also be used to inject fast handlers/pre-filters into requests.
  • REST and Polymorphic Controllers/Resources: ActionController provides a polymorphic way to respond to the URI based on the mime type. That means you can use the same method in the controller, and provide several responses, one in XML, one in PDF, another in JSON, and another in HTML. While you have to write the code anyway, you only have to render the associated view for each mime-type. The controller is simple and easy to understand in its handling of polymorphic requests pointing to the same resource.
  • Coffee Script: It helps developers who don’t want to deal with Javascript syntax and would rather create Javascript code in a more Ruby way. You can take a look here.
  • Rendering engines for All Tastes: On the View side, Rails provides a default rendering engine using ERB templating. However, you can use approaches like HAML or Slim, or create your own.
  • Rake and Command Line Tasks: When you have to do file maintenance for your application–moving files, running upgrade processes, etc.– Rails works with Rake so you can automate tasks in Ruby.
  • Dependencies Easier than Ever: Dependencies weren’t so well-handled in Rails initially, but then the new Bundler appeared (thanks Yehuda Katz (@wycats). It deals with them in a smart, easy-to-maintain way.
  • The Community: One of the keys to success with Rails is the Ruby community itself. It provides events for all flavors, from small to big, from local to global. I highly recommend getting involved and attending events to meet developers in person.

Can I use Rails in my next project?

Yes and no. It depends on what kind of project you’re undertaking, its requirements, and so on. But generally, I think it’ll fit for applications defined with commonplace requirements. Even if it doesn’t, there are certainly other Ruby frameworks you could use. If nothing else, ask the community. (Or me.)

Click here to return to the Ruby on Rails community.

THIS DICE TALENT COMMUNITY SPONSORED BY:

The Latest From Dice

How to Break Into Statistical Programming in Pharma

Posted In Looking in Tech
Pharmaceuticals
Pharmaceutical companies have a seemingly insatiable demand for statistical programmers. Because the process of getting a drug to market requires an inordinate amount of clinical data analysis, they play a key part in the process whether they’re working at a drug company or a clinical research organization. Though a deep understanding of life sciences and significant experience with the clinical process is needed to move into a leadership role, employers in the space are beginning to bring in and train… continue…

The Most Popular Tech Pros

Posted In Looking in Tech
unnamed
With an unemployment rate of less than three percent, just about everyone in technology today is popular with hiring managers and recruiters. That said, professionals in Big Data, mobile, cloud computing and security take being favored to entirely new levels – Will and Kate levels. Click here for more developer jobs. We know because hiring managers are requesting these skilled professionals at record levels as measured by job postings on Dice. Let’s break down the all-time highs: An increasing number… continue…

A NoSQL Alternative: Disk Folders

Folder
One of the joys of programming is that there are often many different ways to accomplish the same goal. That comes in handy when you’re not feeling too confident about a given solution. Consider this problem I recently faced. I was choosing between a relational database or NoSQL for a game server I was working on. Whichever I chose would contain a couple dozen tables and would need to support up to 100,000 users. My real-time needs were very modest,… continue…

How Google Fiber Fighting AT&T Could Boost Your Business

Posted In Looking in Tech
Map of Google Fiber April 2014
AT&T plans on introducing high-speed fiber Internet to 100 cities in 21 metropolitan regions across the United States, although those regions have yet to be decided. “We’re delivering advanced services that offer consumers and small businesses the ability to do more, faster, help communities create a new wave of innovation, and encourage economic development,” Lori Lee, senior executive vice president of AT&T Home Solutions, wrote in a statement. “We’re interested in working with communities that appreciate the value of the… continue…

Software Developers Feel Growing Power

Posted In Looking in Tech
Software Engineer
Software developers have a well-founded confidence in their ability to change the world, according to a survey by IT automation company Chef. And more than half foresee their careers as a path to becoming rich someday. More than two-thirds — 69 percent — of developers describe their profession as “recession-proof,” with opportunities not just at traditional tech companies, but across a range of industries. Indeed, the unemployment rate among all tech occupations fell to 2.7 percent in the first quarter,… continue…

Investors Wary of Startups As Tech Stocks Drop

Posted In Looking in Tech
Stock Market Ticker
The recent downturn in tech stocks has venture capitalists and IPO investors turning cautious. That’s not good news for startups. “We’re obviously in the throes of what feels like a correction for the small-cap and growth-equity companies,” David Golden, managing partner at San Francisco-based Revolution Ventures, told The Wall Street Journal. Jim Breyer, a partner at venture capital firm Accel Partners, said more time in board meetings is being spent on financial strategies. For details on how this impacts you,… continue…

Are Modular Smartphones the Next Big Thing?

Project Ara
Google’s Project Ara wants to take the smartphone back to basics—literally. With Project Ara, the smartphone is modular: The owner can swap out everything from the battery and screen to the speakers and cameras. The device’s endoskeleton holds those modules in place with magnets, meaning those swaps can take place without the need for a mini-screwdriver or other tools. In theory, you could duck into a store, purchase a replacement module for a camera or battery, and pop it into… continue…

Even If Nike’s FuelBand Is Failing, Wearable Tech Isn’t Dead

Nike FuelBand
Over the weekend, CNET reported that Nike planned to lay off employees working on its FuelBand, a “smart bracelet” that tracks the wearer’s physical activity. “As early as this fall, Nike planned on releasing another iteration of the FuelBand—an even slimmer version—but cancelled the project,” the publication reported. “And it appears to have shelved all future physical product projects under the Digital Sport helm, the person familiar with the matter added.” Click here for wearable tech-related jobs. A few days… continue…

2 Little-Known Certifications That Could Get You Promoted

Posted In Looking in Tech
OpenGroup Certified Thumbnail
When it comes to earning certifications, tech professionals always worry about whether it’s worth their time and money. For enterprise architects and IT specialists, there’s some good news: Two credentials earned through the Open Group — including its Open Certified Architect and Open Certified IT Specialist — pay off, though not as you might think. Their value seems to be higher when it comes to moving up within your existing employer, as opposed to getting the attention of new hiring… continue…

This Is the Secret to Landing a Job at athenahealth

Posted In Looking in Tech
Landing@ athenahealth
Health IT vendor athenahealth made news earlier this year when it selected Austin, Texas, as the site of its new R&D hub. The company said it would create 600 jobs there over the next 10 years. However, that’s just one of the locations where athenahealth is hiring in IT. The company will add about 200 tech positions overall this year, according to Technical Recruiting Manager Amber Jackson. She estimates it will bring on more than 100 people in software engineering,… continue…