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

Want Laptop Privacy? Wear This ‘Compubody Sock’

Posted In Living in Tech
Sternlab Compubody
Ever sat on a crowded airplane or bus with your laptop open, craving a little privacy as you typed an email or watched a terrible movie? One valiant innovator has a solution for exactly that dilemma, and it’s a bit more, shall we say, enveloping than one of those privacy filters you slide over your screen. The “Compubody Sock,” which anyone with knitting skills can make at home, is a giant sock-hoodie-bag in which you place your laptop or tablet,… continue…

Always Research an Employer Before Your Interview

Posted In Looking in Tech
Google Search
Tip of the Day Investigating a company and its management team may be one of the most important parts of your job search. In addition to preparing you for the interview, it will help you determine if you’re a good fit for the company—and if it’s a place you really want to work. First, start combing the Web. Give the company’s website a thorough read, paying special attention to the backgrounds of the executive team. Then delve deeper into the… continue…

6 Developer Tips for Better Disaster Recovery

Blue Screen of Death
You go through life thinking that it won’t happen to you, but someday it will: Your development PC suddenly goes from being state-of-the-art to having the computing power of a brick. How quickly you get back into action depends upon your budget and preparedness. Over the recent July 4 weekend it happened to me. The disaster was partially of my own making. Thanks to a slightly dodgy set of RAM—both Ubuntu and Windows 7 memory tests agreed on this—I was… continue…

Why Aren’t Graduates Using Their STEM Degrees?

Posted In Looking in Tech
U.S. Census Bureau
Lots of people earn college degrees in STEM disciplines. But how many of them actually use those degrees for STEM-related work? According to recent data from the U.S. Census Bureau, the answer is, “Not very many.” In a survey of 3.5 million homes, the agency found that almost 75 percent of those who held a bachelor’s degree in a STEM discipline didn’t actually work a STEM job. In a series of interviews with the Washington Post, experts seemed divided about… continue…

4 Interview Qs for Business Analysts in Product or Marketing

Dice Interview Qs Icon
The duties and requirements for business analysts vary from position to position. While some BAs support an entire organization or a particular function, others are tethered to a product or marketing manager and assist in the creation of deliverables for external customers. That can be a tricky role, says Laura Brandenburg, a former BA who trains and coaches prospective professionals for Colorado-based Bridging the Gap. “You may not have access to the external customers who are using your product or… continue…

Don’t Slow Down Your Job Search During the Summer

Posted In Looking in Tech
Beach
Tip of the Day The perception that companies cut back their hiring during the summer is a myth, but job hunting during the hottest months can be tricky. It’s important to avoid two particular hazards: timing and schedules. Because of vacations, trying to schedule interviews can be complicated. An interview process that would typically take three weeks may take five or more. So patience is key. Don’t feel discouraged if the process takes extra time. On the flip side, hiring… continue…

Help Wanted Signs = Dollar Signs for Software Developers

Posted In Looking in Tech
July-Dice-Report-Bonus-Plans-2
Employers are responding to the tight labor market for software developers with a new retention tool: a bonus plan designed specifically for them. Unique bonus programs for software developers have their roots in technology and gaming companies. Now, more employers, in more industries, are adopting targeted plans, according to a recent Dice survey of 700 employers with developers currently on staff. For those companies with bonus plans, one in 10 employers (11 percent) currently have programs tailored exclusively for software… continue…

C++, J2EE, Java Skills Needed in Houston

Posted In Looking in Tech
Downtown Houston
The availability of candidates with the skills for the growing number of open technology jobs in Houston is becoming a worry for local employers, according to the Houston Business Journal. Citing a study from consulting firm CEB, the newspaper says the gap between open jobs and the tech professionals who can fill them has been widening. The greatest demand is for people skilled in C++, J2EE, Java, .NET and cloud computing. Click here to find a tech job in Houston.… continue…

Python, Swift, JavaScript, Java: Best Ways to Learn Them

shutterstock 3d brained
Learning a new programming language—or merely staying adept in ones you know already—is a necessary challenge for programmers and developers who want to stay relevant. Fortunately, every popular programming language comes with tons of documentation, as well as a variety of online tutorials. Check out these handy resources: JavaScript ranks high on everybody’s list of the most popular programming languages. Earlier this summer, for example, tech-industry analyst firm RedMonk drew publicly available data from GitHub and Stack Overflow that suggested… continue…

Responding to Employers, Colleges Focus on Experience

Posted In Looking in Tech
Cogswell professor Albert Chen with his students
Some tech companies—Google notably among them—are de-emphasizing the use of test scores and GPAs in their hiring, and that’s causing colleges and universities to re-think their approach to technical education, says Tech Page One. One reason can be summed up in this quote Google’s senior vice president of people operations, Laszlo Bock, gave to New York Times columnist Tom Friedman: “When you look at people who don’t go to school and make their way in the world, those are exceptional… continue…