Ruby on Rails Interview Questions And Answers

Download Ruby on Rails Interview Questions and Answers PDF

Prepare comprehensively for your Ruby on Rails interview with our extensive list of 16 questions. Each question is designed to test and expand your Ruby on Rails expertise. Suitable for all experience levels, these questions will help you prepare thoroughly. Download the free PDF to have all 16 questions at your fingertips. This resource is designed to boost your confidence and ensure you're interview-ready.

16 Ruby on Rails Questions and Answers:

Ruby on Rails Job Interview Questions Table of Contents:

Ruby on Rails Job Interview Questions and Answers
Ruby on Rails Job Interview Questions and Answers

1 :: What are the differences betweeen Rails 2.x and Rails 3?

(1) Introduction of bundler (New way to manage your gem
dependencies)
* (2) Gemfile and Gemfile.lock (Where all your gem
dependencies lies, instead of environment.rb)
* (3) A new .rb file in config/ folder, named as
application.rb (Which has everything that previously
environment.rb had)
* (4) Change in SQL Structure: Model.where(:activated => true)
* (5) All the mailer script will now be in app/mailers
folder, earlier we kept inside app/models.
* (6) Rails3-UJS support. for links and forms to work as
AJAX, instead of writing complex lines of code, we write
:remote => true
* (7) HTML 5 support.
* (8) Changes in the model based validation syntax:
validates :name, :presence => true
* (9) Ability to install
windows/ruby/jruby/development/production specific gems to
Gemfile.
group :production do
gem 'will_paginate'
end
Read More

2 :: Is it possible to build a 50% bespoke e-commerce platform hence having the ability to customize everything down the line? For example would it make sense to start coding an
application on the Ruby on Rails framework but where the most complex/time consuming code pieces (e.g. shopping cart, etc) can be initially bolted on (hence diminishing
development time and cost) having the ability to change them completely further down the line?

Yes 100% we can build application for e-commerce platform
for example shopify and we have easily integrate the payment
transactions like paypal and authorize.net
Read More

3 :: What i have to do to view my project always on browser?

if u run the server (ruby script/server -d) then the command
line will close ,but server is running.The server will run
until the machine is restart. you can start different port
using ruby script/server -p 3001 -d
Read More

4 :: Is Ruby is a Scripting Language or Compiled Language?

In general, programming languages fall into one of two
categories: they're either compiled languages or scripting
languages. Let's explore what each of those terms means, and
understand the differences between them.

Compiled Languages: The language in which you write an
application is not actually something that your computer
understands. Your code needs to be translated into bits and
bytes that can be executed by your computer. This process of
translation is called compilation, and any language that
requires compilation is referred to as a compiled language.
Examples of compiled languages include C, C#, and Java.

For a compiled language, the actual compilation is the final
step in the development process. You invoke a compiler --
the software program that translates your final
hand-written, human-readable code into machine-readable code
-- and the compiler creates an executable file. This final
product is then able to execute independently of the
original source code.

Thus, if you make changes to your code, and you want those
changes to be incorporated into the application, you must
stop the running application, recompile it, then start the
application again.

Scripting Languages: On the other hand, a scripting language
such as Ruby, PHP, or Python, relies upon an application's
source code all of the time. Scripting languages don't have
a compiler or a compilation phase per se; instead, they use
an interpreter -- a program that runs on the web server --
to translate hand-written code into machine-executable code
on the fly. The link between the running application and
your hand-crafted code is never severed, because that
scripting code is translated every time it is invoked -- in
other words, for every web page that your application renders.

As you might have gathered from the name, the use of an
interpreter rather than a compiler is the major difference
between a scripting language and a compiled language.

The Great Performance Debate: If you've come from a
compiled-language background, you might be concerned by all
this talk of translating code on the fly -- how does it
affect the application's performance?

These concerns are valid -- translating code on the web
server every time it's needed is certainly more expensive,
performance-wise, than executing pre-compiled code, as it
requires more effort on the part of your machine's
processor. The good news is that there are ways to speed up
scripted languages, including techniques such as code
caching and persistent interpreters. However, both topics
are beyond the scope of this book.

There's also an upside to scripted languages in terms of
performance -- namely, your performance while developing an
application.

Imagine that you've just compiled a shiny new Java
application, and launched it for the first time ... and then
you notice a typo on the welcome screen. To fix it, you have
to stop your application, go back to the source code, fix
the typo, wait for the code to recompile, and restart your
application to confirm that it is fixed. And if you find
another typo, you'll need to repeat that process again.
Lather, rinse, repeat.

In a scripting language, you can fix the typo and just
reload the page in your browser -- no restart, no recompile,
no nothing. It's as simple as that.
Read More
Model, View and Controller(MVC) is 3 tier architecture.
view consits all HTML, javscript pages. its client side
template. while as Model connects to Database describing all
data fields and the relation between then and all business
calculations are controlled by controller
Read More

6 :: What is the functionality of Model views and controllers?

Model: Model is responsible for maintaining the database.

views: View is responsible for generating user interface.

controllers: Getting input request from browser and generate
outgoing response.
Read More

7 :: What is the difference between sessions and flash?

Session is only for store the small amount of user
data,which data not stored permanently that's when we logged
out from our application.. which session value will removed.
But Flash is used to display the some messages like error
message and useful information messages in view pages...
Read More

8 :: What are filters? and how many types of filters are there in ruby?

Filters enable controllers to run shared pre and post
processing code for its actions.

Filter methods are macro-style, that is, they appear at the
top of your controller method, inside the class context,
before method definitions.

the below types of filters in ruby

before_filter,
after_filter,
prepend_before_filter,
prepend_after_filter,
around_filter
Read More

9 :: what is ruby software and where and when it is usefull.
Is it usefull to data base developer, if yes...where?

Ruby is Dynamic object oriented programming language . we
can use it for any application like java, or we can use it
for web programming language
Read More

10 :: How will be the future for ruby on rails?

Ruby On Rails developed in 1992.But now it is spreading all
over.Coding using ROR is easy we can easily develop web
applications.We can develop webservers and Ajax also can b
implemented in ROR.Similarly we have some disadvantages in
it like the User Interface and easily can do the wrong
things.Finally It is easy to learn and easy to implement
also.Learn it,It has good future.
Read More

11 :: What is difference between form_for and form_tag?

form_for and form_tag both are used to submit the form in
ruby on rails.
but the way of handling objects related to model is
different.

form_for:

you should use form_for for a specific model i.e while
crating an new row in database. form_for will perform the
standard http post which is having fields related to active
record objects.

here is the example for using form_for in ruby on rails:

<% form_for :user, @user, :url => { :action => "update" }
do |f| %>

then in here you can use the f object to create input
field.

First name: <%= f.text_field :firstname %>
Last name : <%= f.text_field :lastname %>
Biography : <%= f.text_area :biography %>

<% end %>

form_tag:

form_tag just creates an form as an normal form. form_for
will perform the standard http post without any model
backed and has normal fields. this is used mainly when
specific things need to be submitted via form


here is the example for using form_tag in ruby on rails:

<% form_tag '/posts' do -%>
<%= text_field_tag "post", "firstname" %>
<% end -%>
Read More

12 :: Why do we use request.xhr? in rails?

Conventional web application transmit information to and
from the sever using synchronous requests. This means you
fill out a form, hit submit, and get directed to a new page
with new information from the server.
When you interact with an Ajax-powered web page, it loads an
Ajax engine in the background. In response to an event web
application passes asynchronous request (XMLHttpRequest or
xhr). In fact it is javaScript object/method that performs
asynchronous interaction with the server, JavaScript object
that performs asynchronous interaction with the server and
behind the scene fetches data. and behind the scene fetches
data.
We do request.xhr? only to check the request type, either
its AJAX request or others(post, get).
Read More

13 :: what the difference between static scaffolding and Dynamic scaffolding?

With Rails 2.0, you may have noticed that dynamic
scaffolding breaks–that is, if you have a controller with
scaffold :model_name in it, all the scaffolded actions–new,
delete, index–no longer exist! In Rails 2.0, you can only
generate static scaffolding–that is, you can use the
scaffold to generate the files for controllers, models, and
views.

What’s more, Rails 2.0 allows you to specify the model
attributes inside the scaffold. This then creates views with
all the appropriate fields, and it also creates the
migration with all the fields in it! Excellent!

As an example, say we wanted to create a blog-post model. We
could generate it like so:

script/generate scaffold Post title:string content:text
category_id:integer

You’ll notice Rails will generate, among other things:

► A post.rb model file
► A posts_controller.rb controller file
► A posts view folder containing views for the index, show, new, and edit actions
► A DB migration called xxx_create_posts
► A unit-test, fixtures file, and helper

Everything you need–indeed, everything the dynamic
scaffolding provided–is included, albeit as static content.
All you need to do is migrate your DB and you’re up and flying!

So the main difference is, with dynamic scaffolding you can
generate new, edit and delete methods but with static
scaffolding you can't
Read More

14 :: Whats the difference between symbol and string?

Rails makes extensive use of symbols. A symbol looks like a
variable symbols name, but it’s prefixed with a colon.
Examples of symbols include :action,:line_items, and :id.

Rails uses symbols to identify things. In particular, it
uses them as keys when naming method parameters and looking
things up in hashes. For example:
redirect_to :action => "edit", :id => params[:id]
Read More

15 :: What is session and cookies?

Session is used for maintaining the particular value
throughout the session..(browser closed)

e.x: session[:value]="poornimad"

this values is not changed until the browser closed..

Cookies:
*********
This is used to store the values in the Browser..this
value is not delete till the cookies are deleted..This
cookies concept is same as Java cookies.The concept is same.
Read More

16 :: Why RubyonRails?

Super productive new way to develop web applications because:

1. Dynamically typed programming language similar to Python,
Smalltalk, and Perl(Templating language)
2. Follows Model-View-Controller (MVC) architecture
3. Strives for simplicity
4. Less coding.
5. Minimum Configuration.
6. Design patterns admire
7. Light webserver
8. ORM
Read More