Ruby On Rails Flashcards ionicons-v5-c

What are the various components of Rails

Action Pack (Action Controller, Action View), Action Dispatch, Action Mailer, Action Model, Active Record, Active Resource, Active Support

What is Action View

Action View manages the views of the Rails application. It can create both HTML and XML output by default. It manages rendering templates, including nested and partial templates, and includes built-in AJAX support

What is Action Dispatch

Handles routing of the web requests and dispatches them as you want, either to your application or any other Rack application

What is Action Mailer

Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.

What is Rack

a Rack application is a thing that responds to #call and takes a hash as argument, returning an array of status, headers and a body. The body needs to respond to #each and then successively return strings that represent the response body. The hash given contains a CGI-ish set of environment variables and some special values, like the body stream of the request (env['rack.input']), or information about the run-time environment (e.g. env['rack.run_once']).Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

What is Active Model

Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.

What is Active Record

Like ORM where classes are mapped to table. Objects are mapped to columns and object attributes are mapped to data in the table.

What is Active Resource

Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics

What is Active Support

Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails both by the core code and by your applications

Explain about RESTful Architecture

REST stands for Representational State Transfer. REST is an architecture for designing both web applications and application programming interfaces (API's), that's uses HTTP.To have a RESTFul interface means clean URLs, less code, CRUD (Create, Read, Update, Destroy).

Render Vs Redirect_to

render will render a particular view using the instance variables available in the action. For example if a render was used for the new action, when a user goes to /new, the new action in the controller is called, instance variables are created and then passed to the new view. Rails creates the html for that view and returns it back to the user's browser. This is what you would consider a normal page load.redirect_to will send a redirect to the user's browser telling it to re-request a new URL. Then the browser will send a new request to that URL and it will go through the action for that URL, oblivious to the fact that it was redirected to. None of the variables created in the action that caused the redirect will be available to the redirected view. This is what happens when you click on 'Create' in a form and the object is created and you're redirected to the edit view for that object.f you need to render another action's view, you can use render :action_name. For example if the user has filled in a form at /new and they click 'Create', the form is posted to the create action. If there are errors with creating the object, in the create action you can use render :new to show the same form as before but with the error messages for why the object failed to be created. These errors can be displayed because the new template will have access to the variables in the create action. If you used redirect_to here, you wouldn't be able to show the errors and anything typed into the form would be lost.If you need the user to run a new action, use redirect_to :action => :action_name. For example if the user has clicked 'Create' and there are no errors in creating the object, you can use redirect_to :action => :show to show the successfully created object.

How many types of Association Relationships does a Model have?

1) One-to-One: When one item has exactly one of another item. Ex, A person has exactly one birthday.2) One-to-Many: When one object can be a member of many other objects. For example, one subject can have many books.3) Many-to-Many: Object is related to one or more of a second object, and the second object is related to one or many of the first object.You indicate these associations by adding declarations to your models:has_on, has_many, belongs_to, and has_and_belongs_to_many.

What are helpers and how to use helpers in ROR

Helpers are modules that provide methods which are automatically usable in your view. They provide shortcuts to commonly used display code and a way for users to keep the programming out of the views. The purpose of a helper is to simplify the view.

Define filters

Filters are methods that run 'before', 'after' or 'around' a controller action. Filters are inherited.

GET vs POST methods

GET is basically for just getting (retrieving) data, whereas POST may involve anything, like storing or updating data, or ordering a product, or sending E-mail.