Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Ruby On Rails Interview Questions and Answers

Ques 51. How can you send a MULTI-PART Email?


Nowadays most email clients support HTML email, however there are still some old Blackberry phones that prefer emails the ‘ol text way. 

Therefore it is important to send emails both as HTML and text. This technique is called multi-part emails. 

The ActionMailer class (included in Rails 3.0) does a great job of sending both text and HTML emails out to the end user at the same time. 

By default Rails sending an email with plain/text content_type, for example:

# app/models/notifier.rb
def send_email(email)
  subject       email.subject
  from          email.from
  recipients    email.recipients
  body          :email => email

Next let’s update the view in : app/views/notifier/send_email.html.erb

Welcome to here: 

The sent email is a plain text email

Date: Thu, 5 Aug 2010 16:38:07 +0800
From: RailsBP 
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8


The link url is just displayed as a plain text because of the email content_type.


If we want the email clients to display link url as html format, we should change the content_type to text/html in the app/models/notifier.rb file

def send_email(email)
  subject          email.subject
  from             email.from
  recipients       email.recipients
  content_type     "text/html"
  body             :email => email

Now the sent email is a html formatted email

Date: Thu, 5 Aug 2010 17:32:27 +0800
From: RailsBP 
Mime-Version: 1.0
Content-Type: text/html; charset=utf-8


Now the email client can display the link url correctly with html format.

The email header looks somewhat like this:

Content-Type: multipart/alternative;
Content-Type: multipart/alternative tells the e-mail program to expect different parts to follow, separated by a boundary which specified in quotation marks. Actually the boundary could be anything, though hyphens, equal signs, and underscores insure that the e-mail program won't try to display this boundary to the recipient.
Content-Type: text/plain;
Content-Transfer-Encoding: 8bit

Is it helpful? Add Comment View Comments
Ques 52. What is the purpose of Layouts in Ruby on Rails?

Layouts are partial ruby/html files that are used to render the content pages. 

There are placed in the folder: app/views/layouts

Items that you would typically put in this folder are things like headers/footers, navigation elements, etc.

Here’s a sample layout file: /app/views/layout/application.html.erb

<html lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Learning System | <%= @page_title || 'Admin Area' %></title>
    <meta name="author" content="Anil Punjabi">
    <%= stylesheet_link_tag('public', 'admin', :media => 'all') %>
    <%= javascript_include_tag('application') %>
    <div id="header">
      <h1>Learning System</h1>
    <div id="main">
      <% if !flash[:notice].blank? %>
      <div class="notice">
        <%= flash[:notice] %>
      <% end %>
      <div id="content">
        <%= yield %>
    <div id="footer">
      <p id="copyright">© / Anil Punjabi</p>
Say you are trying to access the page as shown below:
Then the contents of the index.html.erb would be placed above in the section shown under <% yield %> above and sent back to the user.
Is it helpful? Add Comment View Comments
Ans. That is the purpose of layouts. You embed partial views inside the file /app/views/layout/application.html.erb and then whenever you render any page this layout is merged with it.
Is it helpful? Add Comment View Comments
Ques 54. What is Rake in Ruby on Rails?

Rake is a popular ruby gem that makes the job of running tasks simpler. 

Rake is most often used for DB tasks, but it can be used for m

The common DB commands are:

rake db:migrate
rake db:reset

You can use cron to schedule rake tasks. 

Sometimes you would create a dataloader.rake file and put it in the lib/tasks folder so that it can be used to populate the database on startup.

Is it helpful? Add Comment View Comments
Ques 55. What is Capistrano?
Ans. Capistrano is a popular deployment tool — it allows developers to push code from their desktop to the servers. 
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2020 WithoutBook