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

Healthcare IT Consultants Happier Than Full-Timers

Health IT
Consultants involved in implementing healthcare IT solutions are generally happier with their work than their full-time counterparts, according to a survey by Atlanta-based staffing firm Healthcare IT Leaders. More than three quarters—77 percent—of the consultants said they were either “very satisfied” or “somewhat satisfied” with their jobs, the survey found. That compares to 64 percent of full-time healthcare IT employees. To put the numbers in context, other surveys have found that 72 percent of workers across all industries report similar… continue…

Have Code to Go Along With Your Resume

Posted In Looking in Tech
Printed Code
Tip of the Day When you’re a software engineer, the resume is a tricky beast. It can describe the technologies you’ve worked with, but can’t say what you were able to do with them or show a hiring manager how well-structured your code is or how scalable your designs are. Hiring managers want to know how you produce software, preferably in an environment like the one they’re going to put you in. Additionally, they need to know that you can… continue…

Is There a Future in Programming D?

D Programming Language Thumbnail
Over at HTML5Report.com, Steve Anderson is wondering if D is the next big programming language. D took form when Walter Bright and Andrei Alexandrescu combined their efforts to develop a new language back in 2005. The result, says Anderson, offers some “very exciting” possibilities, and he notes that the ad-tech firm Sociomantic Labs, recently acquired by Tesco for $200 million, used D to build its online system. Making things more interesting is another online company’s interest in D: Facebook. Click… continue…

Companies Feel Pressure to Hire CISOs

Posted In Looking in Tech
Mobile Security
In the relatively brief time it’s been around, the Chief Information Security Officer’s job has developed into a pressured, thankless existence. These are the executives charged with keeping an organization’s systems secure in the face of mounting cyberattacks, careless vendors, and employees who are more concerned with using their own iPhones than keeping company data secure. “This job is not for the fainthearted,” David Jordan, CISO for Virginia’s Arlington County, told The New York Times. Click here to find CISO… continue…

10 Top College Robotics Programs

Posted In Looking in Tech
MIT Robotics
Love it or fear it, the trend toward building more sophisticated robots isn’t going to abate any time soon. Indeed, given their potential to impact everything from transportation to medicine, the need for engineers skilled in robotics is bound to increase. A tidbit: Mechanical engineering ranked fifth on the National Association of Colleges and Employers’ list of most in-demand bachelor’s degrees. So where do you learn to build robots? Business Insider put together a list of 10 universities where you… continue…

2 Networking Tricks for Shy People

Posted In Looking in Tech
Networking
Tip of the Day You don’t have to be the life of the party to have a vibrant network. Select the formats and venues where you’re the most comfortable, and get the ball rolling by building a small circle of contacts. If you’re uncomfortable by yourself, go with a friend or colleague. That way, you can break the ice by making introductions and engaging in small group conversations. You may find it’s easier to get started by remembering that everyone’s… continue…

How to Land a Job at Ernst & Young

Posted In Looking in Tech
Landing@ Ernst & Young
Ernst & Young, also known as “EY,” is a global leader in assurance, tax, transaction and advisory services. The company has about 175,000 employees in over 150 countries, some 54,000 of whom are in the Americas. Currently, more than 4,000 professionals work in EY’s IT operations. “At EY, we have many opportunities for individuals with backgrounds in technology in all of our service lines,” says Larry Nash, EY Americas director of experienced & executive recruiting. Primarily a Microsoft shop, the… continue…

Internet of Things Increases Need for Security Pros

Smart Home
The sheer number of “things” to be secured in the Internet of Things is expected to create a rash of jobs in cybersecurity over the next several years. “You’re going to have to secure the device or the sensor, you need to secure the data, and you’re going to have to secure that across an open network,” Intel’s head of business marketing, Stuart Dommett, told an IoT roundtable in May. “It really is a massive, massive change.” Click here to… continue…

Download Apollo 11′s Source Code

Posted In Living in Tech
David Woods
This weekend’s 45th anniversary of the Apollo 11 moon landing reminded everyone of what one nation can accomplish if it has enough money, engineering ingenuity and people willing to strap themselves into a rocket bound for space. Despite its impressive hardware, NASA’s computing power for the mission seems paltry by modern standards. The agency’s Goddard Space Flight Center relied on IBM System/360 Model 75 mainframes to maintain communications with Apollo 11, running programs no more than a few megabytes in… continue…

Is This New Cyber Forensics Certification Worth the Investment?

(ISC)²
Continued pressure on cybersecurity systems is making professionals with security and forensic experience extremely attractive to employers. Not surprisingly, related certifications are gaining more attention, including one of the newer ones: the CCFP, or Certified Cyber Forensics Professional from the (ISC)². According to (ISC)² Executive Director W. Hord Tipton, the organization saw a need for a certification that was broader than those available for professionals working in and around law enforcement, intelligence, litigation, consulting and computer security. The CCFP’s target… continue…