Rails ActiveRecord package uses Rubys metaprogramming and convention over

Rails activerecord package uses rubys metaprogramming

This preview shows page 134 - 136 out of 517 pages.

Rails’ ActiveRecord package uses Ruby’s metaprogramming and convention over configuration to free you from writing any code at all to perform the basic Create, Read, Update and Delete (CRUD) operations on your models, as long as you follow certain conventions about naming classes and variables. Rails’ ActionView and ActionController packages provide help for creating Web pages, dealing with fill-in forms, and setting up the routes that map URIs to controller actions (code in your app). A properly-constructed Rails app can be easily adapted to work in a service-oriented architecture, communicating with external services rather than with a human using a browser. Debugging SaaS requires understanding the different places something could go wrong during the flow of a SaaS request, and making that information visible to the developer. All of these Rails facilities are designed to streamline the creation of apps that will work in a Service- Oriented Architecture and exploit proven design patterns for SaaS.
Image of page 134
4.1 Rails Basics: From Zero to CRUD As we saw in Chapter 2 , Rails is a SaaS application framework that defines a particular structure for organizing your application’s code and provides an interface to a Rails application server such as Rack. The app server waits for a Web browser to contact your app and maps every incoming request (URI and HTTP method) to a particular action in one of your app’s controllers. Rails consists of both the framework itself and a new command rails that is used to set up and manipulate Rails apps. Three main modules make up the heart of Rails’ support for MVC: ActiveRecord for creating models, ActionView for creating views, and ActionController for creating controllers. Using the explanation of Model–View–Controller in Chapter 2 as a reference framework, we will start from zero and create the Rotten Potatoes app described in Chapter 2 for maintaining a simple database of movie information. We will briefly visit each of the “moving parts” of a basic Rails application with a single model, in the following order: 1. Creating the skeleton of a new app 2. Routing 3. The database and migrations 4. Models and Active Record 5. Controllers, views, forms, and CRUD -T omits directories for tests that use Ruby’s Test::Unit framework, since in Chapter 8 we will use the RSpec testing framework instead. rails --help shows more options for creating a new app. Begin by logging into the bookware VM, changing to a convenient directory such as Documents ( cd Documents ), and creating a new, empty Rails app with rails new myrottenpotatoes -T . If all goes well, you’ll see several messages about files being created, ending with “Your bundle is complete.” You can now cd to the newly-created myrottenpotatoes directory, called the app root directory for your new app. From now on, unless we say otherwise, all file names will be relative to the app root.
Image of page 135
Image of page 136

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors