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 sent_on Time.now body :email => email end
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 To: email@example.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Welcome: http://rails-bestpractices.com
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 sent_on Time.now content_type "text/html" body :email => email end
Now the sent email is a html formatted email
Date: Thu, 5 Aug 2010 17:32:27 +0800 From: RailsBP To: firstname.lastname@example.org Mime-Version: 1.0 Content-Type: text/html; charset=utf-8 Welcome: http://rails-bestpractices.com
Now the email client can display the link url correctly with html format.
The email header looks somewhat like this:
Content-Type: multipart/alternative; boundary="----=_NextPart_000_002C_01BFABBF.4A7D6BA0" 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. ------=_NextPart_000_002C_01BFABBF.4A7D6BA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit
Ques 52. What is the purpose of Layouts in Ruby on Rails?Ans.
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
Ques 53. IS IT POSSIBLE TO EMBED PARTIAL VIEWS INSIDE LAYOUTS? HOW?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.
Ques 54. What is Rake in Ruby on Rails?Ans.
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.
Ques 55. What is Capistrano?Ans. Capistrano is a popular deployment tool — it allows developers to push code from their desktop to the servers.
Most helpful rated by users: