Skip to main content

Ruby On Rails Interview Questions for Freshers...

1. Why Ruby on Rails?
Ans: There are lot of advantages of using ruby on rails
1. DRY Principal
2. Convention over Configuration
3. Gems and Plugins
4. Scaffolding
5. Pure OOP Concept
6. Rest Support
7. Rack support
8. Action Mailer
9. Rpc support
10. Rexml Support
11. etc..


2. Explain about the programming language ruby?
Ruby is the brain child of a Japanese programmer Matz. He created Ruby. It is a cross platform object oriented language. It helps you in knowing what your code does in your application. With legacy code it gives you the power of administration and organization tasks. Being open source, it did go into great lengths of development.

3. Explain about ruby names?
Classes, variables, methods, constants and modules can be referred by ruby names. When you want to distinguish between various names you can specify that by the first character of the name. Some of the names are used as reserve words which should not be used for any other purpose. A name can be lowercase letter, upper case letter, number, or an underscore, make sure that you follow the name by name characters.


4. What is the Difference between Symbol and String?
Ans: Symbol are same like string but both behaviors is different based on object_id, memory and process time (cpu time) Strings are mutable , Symbols are immutable.
Mutable objects can be changed after assignment while immutable objects can only be overwritten. For example
p "string object jak".object_id #=> 22956070
p "string object jak".object_id #=> 22956030
p "string object jak".object_id #=> 22956090

p :symbol_object_jak.object_id #=> 247378
p :symbol_object_jak.object_id #=> 247378
p :symbol_object_jak.object_id #=> 247378

p " string object jak ".to_sym.object_id #=> 247518
p " string object jak ".to_sym.object_id #=> 247518
p " string object jak ".to_sym.object_id #=> 247518

p :symbol_object_jak.to_s.object_id #=> 22704460
p :symbol_object_jak.to_s.object_id #=> 22687010
p :symbol_object_jak.to_s.object_id #=> 21141310

And also it will differ by process time
For example:
Testing two symbol values for equality (or non-equality) is faster than testing two string values for equality,
Note : Each unique string value has an associated symbol

5. What is Session and Cookies?
Ans: Session: are used to store user information on the server side.
cookies: are used to store information on the browser side or we can say client side
Session : say session[:user] = “arunkumar” it remains when the browser is not closed

6. What is request.xhr?
Ans: A request.xhr tells the controller that the new st="on"Ajax request has come, It always return Boolean values (TRUE or FALSE)
7. What is MVC? and how it Works?
Ans: MVC tends for Model-View-Controller, used by many languages like PHP, Perl, Python etc. The flow goes like this: Request first comes to the controller, controller finds and appropriate view and interacts with model, model interacts with your database and send the response to controller then controller based on the response give the output parameter to view, for Example your url is something like this:
http://localhost:3000/users/new
here users is your controller and new is your method, there must be a file in your views/users folder named new.html.erb, so once the submit button is pressed, User model or whatever defined in the rhtml form_for syntax, will be called and values will be stored into the database.
8. What things we can define in the model?
Ans: There are lot of things you can define in models few are:
1. Validations (like validates_presence_of, numeracility_of, format_of etc.)
2. Relationships(like has_one, has_many, HABTM etc.)
3. Callbacks(like before_save, after_save, before_create etc.)
4. Suppose you installed a plugin say validation_group, So you can also define validation_group settings in your model
5. ROR Queries in Sql
6. Active record Associations Relationship
9. What is ORM in Rails?
Ans: ORM tends for Object-Relationship-Model, it means that your Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.
10. How many Types of Associations Relationships does a Model has?
Ans: When you have more than one model in your rails application, you would need to create connection between those models. You can do this via associations. Active Record supports three types of associations:
one-to-one : A one-to-one relationship exists when one item has exactly one of another item. For example, a person has exactly one birthday or a dog has exactly one owner.
one-to-many : A one-to-many relationship exists when a single object can be a member of many other objects. For instance, one subject can have many books.
many-to-many : A many-to-many relationship exists when the first 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_one, has_many, belongs_to, and has_and_belongs_to_many.
11. Difference between render and redirect?
Ans:
render example:
 render :partial
 render :new
  It will render the template new.rhtml without
  calling or redirecting to the new action.

redirect example:
 redirect_to :controller => ‘users’, :action => ‘new’
  It forces the clients browser to request the
  new action.

12. What is the Difference between Static and Dynamic Scaffolding?
Ans: The Syntax of Static Scaffold is like this:
ruby script/generate scaffold User Comment
Where Comment is the model and User is your controller, So all n all static scaffold takes 2 parameter i.e your controller name and model name, whereas in dynamic scaffolding you have to define controller and model one by one.

13. How you run your Rails Application without creating database ?
Ans: You can run application by uncomment the line in environment.rb
Path => rootpath conf/ environment.rb

# Skip frameworks you're not going to use (only works if using vendor/rails)
    config.frameworks -= [ :action_web_service, :action_mailer,:active_record ]
14. How to use sql db or mysql db. without defining it in the database.yml
Ans: You can use ActiveRecord anywhere!
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection({
:adapter => 'postgresql',
:user => 'foo',
:password => 'bar',
:database => 'whatever'
})
class Task <>
set_table_tame "a_legacy_thingie"
def utility_methods
update_attribute(:title, "yep")
end
end
Task.find(:first)
Etcetera. It’s ActiveRecord, you know what to do. Going wild:
ActiveRecord::Base.establish_connection(:adapter => "sqlite3",
:dbfile => ":memory:")
ActiveRecord::Schema.define(:version => 1) do
create_table :posts do |t|
t.string :title
t.text :excerpt, :body
end
end
class Post <>
validates_presence_of :title
end
Post.create(:title => "A new post!")
Post.create(:title => "Another post",
:excerpt => "The excerpt is an excerpt.")
puts Post.count
15. What are helpers and how to use helpers in ROR?
Ans: Helpers (“view 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 you to keep the programming out of your views. The purpose of a helper is to simplify the view. It’s best if the view file (RHTML/RXML) is short and sweet, so you can see the structure of the output.
16. What is Active Record?
Ans: Active Record are like Object Relational Mapping(ORM), where classes are mapped to table , objects are mapped to columns and object attributes are mapped to data in the table
17. Ruby Support Single Inheritance/Multiple Inheritance or Both?
Ans: Ruby Supports only Single Inheritance.
You can achieve Multiple Inheritance through MIXIN concept means you achieve using module by including it with classes.
18. How many types of callbacks available in ROR?
Ans:
(-) save
(-) valid
(1) before_validation
(2) before_validation_on_create
(-) validate
(-) validate_on_create
(3) after_validation
(4) after_validation_on_create
(5) before_save
(6) before_create
(-) create
(7) after_create
(8) after_save

19. What can Rails Migration do?
Ans:
create_table(name, options)
drop_table(name)
rename_table(old_name, new_name)
add_column(table_name, column_name, type, options)
rename_column(table_name, column_name, new_column_name)
change_column(table_name, column_name, type, options)
remove_column(table_name, column_name)
add_index(table_name, column_name, index_type)
remove_index(table_name, column_name)
Migrations support all the basic data types: string, text, integer, float, datetime, timestamp, time, date, binary and boolean:
string - is for small data types such as a title.
text - is for longer pieces of textual data, such as the description.
integer - is for whole numbers.
float - is for decimals.
datetime and timestamp - store the date and time into a column.
date and time - store either the date only or time only.
binary - is for storing data such as images, audio, or movies.
boolean - is for storing true or false values.
Valid column options are:
limit ( :limit => “50” )
default (:default => “blah” )
null (:null => false implies NOT NULL)

20. What is the naming conventions for methods that return a boolean result?
Ans: Methods that return a boolean result are typically named with a ending question mark. For example: def active? return true #just always returning true end


21. How do the following methods differ: @my_string.strip and @my_string.strip! ?
Ans: The strip! method modifies the variable directly. Calling strip (without the !) returns a copy of the variable with the modifications, the original variable is not altered.
22. What's the difference in scope for these two variables: @name and @@name?
Ans: @name is an instance variable and @@name is a class variable
23. What is the log that has to seen to check for an error in ruby rails?
Ans: Rails will report errors from Apache in log/apache.log and errors from the Ruby code in log/development.log. If you're having a problem, do have a look at what these logs are saying. On Unix and Mac OS X you may run tail -f log/development.log in a separate terminal to monitor your application's execution.

24. What is the use of global variable $ in Ruby?
Ans: A class variable starts with an @@ sign which is immediately followed by upper or lower case letter. You can also put some name characters after the letters which stand to be a pure optional. A class variable can be shared among all the objects of a class. A single copy of a class variable exists for each and every given class.
To write a global variable you start the variable with a $ sign which should be followed by a name character. Ruby defines a number of global variables which also include other punctuation characters such as $_ and $-k.
For example: If you declare one variable as global we can access any where, where as class variable visibility only in the class Example
class Test
def h
 $a = 5
 @b = 4
Â
while $a > 0
puts $a
$a= $a - 1
end
end
end
test = Test.new
test.h
puts $a                    # 5
puts @b                   #nil


25. Where does the start_tabnav gets informations for tabs rendering in ruby rail?
Ans: The main Symbol let the start_tabnav method know to look for a special MainTabnav class where all the magic happens


26. What is the Install rail package?
Ans: There are several packages that you can download and install. The prebuilt Rails installer called Install rail which currently is only for Windows
27. What is the log that has to seen to check for an error in ruby rails?
Ans: Rails will report errors from Apache in log/apache.log and errors from the Ruby code in log/development.log. If you're having a problem, do have a look at what these logs are saying. On Unix and Mac OS X you may run tail -f log/development.log in a separate terminal to monitor your application's execution.

28. What is the use of super in ruby rails?
Ans: Ruby uses the super keyword to call the superclass (Parent class) implementation of the current method

29. What is the difference between nil and false in ruby?
Ans: False is a boolean datatype, Nil is not a data type it have object_id 4

30. How is class methods defined in Ruby?
Ans: A:def self.methodname
--------
--------
end
or
def classname.methodname
--------
--------
end

31. How is object methods defined in Ruby?
Ans:
class jak
def method1
--------
--------
end
end
obj=jak.new

It is single object
def obj.object_method_one
--------
--------
end

obj.Send(object_method_every)

It will be created every for every object creation

32. What are the priority of operators available in Ruby ?
Ans: Something that used in an expression to manipulate objects such as + (plus), - (minus), * (multiply), and / (divide). You can also use operators to do comparisons,such as with <, >, and &&. The priority is based on "BODMAS"


33. What are the looping structures available in Ruby?
Ans: for..in
untill..end
while..end
do..end
Note: You can also use each to iterate a array as loop not exactly like loop
34. What are the object-oriented programming features supported by Ruby and how multiple inheritance supported in ?
Ans: Classes,Objects,Inheritance,Singleton methods,polymorphism(accomplished by over riding and overloading) are some oo concepts supported by ruby. Multiple inheritance supported using Mixin concept.

35. What is the scope of a local variable in Ruby and define it scope ?
Ans: A new scope for a local variable is introduced in the toplevel, a class (module) definition, a method defintion. In a procedure block a new scope is introduced but you can access to a local variable outside the block.
The scope in a block is special because a local variable should be localized in Thread and Proc objects.

36. How is an enumerator iterator handled in Ruby?
Ans: Iterator is handled using keyword 'each' in ruby.
For example
number=[1,2,3]
then we can use iterator as
number.each do |i|
puts i
end
Above prints the values of an array $no which is accomplished using iterator.
37. How is visibility of methods changed in Ruby (Encapsulation)?
Ans: By applying the access modifier : Public , Private and Protected access Modifier


38. What is the use of load,require, auto_load,require_relative in Ruby?
Ans: A method that loads and processes the Ruby code from a separate file, including whatever classes, modules, methods, and constants are in that file into the current scope. load is similar, but rather than performing the inclusion operation once, it reprocesses the code every time load is called.
auto_load - Whenever the interpreter call the method that time only it will initiate the method in hat file.
require_relative - It it to load local folder files.

More Questions:
1. Explain choose_weighted method with example
2. What is GIL in ruby ?
3. Is variable is a object ?
Ans : Variable is not an object
4. List of protocols supported by ruby ?
5. Explain Virtual attribute ?
6. How to validate and modify attribute value ?
7. How to serialize data with YAML ?

More Questions and Answers of this will be published very soon , So stay in touch.. I will keep you updating.....





Hi Guys, Hope you all are fine, Well I think that I should Post something different in my blog, so that It will help you to get some more knowledge  , So I came with Interview Questions, Hope this will help you a lot, I will update it regularly, If I found something Interesting. Well If you are experienced, I hope this should help you. All the Questions are dynamically Typed.
Q1. What is request.xhr?
Sol: A request.xhr tells the controller that the new Ajax request has come, It always return TRUE or FALSE
Q2. What is the Difference between Static and Dynamic Scaffolding?
Sol: The Syntax of Static Scaffold is like this:
ruby script/generate scaffold User Comment
Where Comment is the model and User is your controller, So all n all static scaffold takes 2 parameter i.e your controller name and model name, whereas in dynamic scaffolding you have to define controller and model one by one.
Q3. What is the Difference between Symbol and String?
Q4. What is Session and Cookies?
Sol: Session: are used to store user information on the server side.
cookies: are used to store information on the browser side or we can say client side
Session : say session[:user] = “puneet” it remains when the browser is not closed
Q5. Why Ruby on Rails?
Sol: There are lot of advantages of using ruby
1. DRY Principal
2. Convention over Configuration
3. Gems and Plugins
4. Scaffolding
5. Pure OOP Concept
Q6. What is MVC? and how it Works?
Sol: MVC tends for Model-View-Controller, used by many languages like PHP, Perl, Python etc. The flow goes like this: Request first comes to the controller, controller finds and appropriate view, your view interacts with model, model interacts with your database, for Example your url is something like this:
http://localhost:3000/users/new
here users is your controller and new is your method, there must be a file in your views/users folder named new.html.erb, so once the submit button is pressed, User model or whatever defined in the rhtml form_for syntax, will be called and values will be stored into the database.
Q7. What things we can define in the model?
Sol: There are lot of things you can define in models few are:
1. Validations (like validates_presence_of, numeracility_of, format_of etc.)
2. Relationships(like has_one, has_many, HABTM etc.)
3. Callbacks(like before_save, after_save, before_create etc.)
4. Suppose you installed a plugin say validation_group, So you can also define validation_group settings in your model
5. ROR Queries in Sql
Q8. What is ORM in Rails?
Sol: ORM tends for Object-Relationship-Model, it means that your Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.
Q9. How many Types of Relationships does a Model has?
Sol: * (1) has_one
* (2) belongs_to
* (3) has_many
* (4) has_many :through
Q10. What is the difference between has_and_belongs_to_many and has_many :through ?
Q11.  What is the difference between rails version 2.2.2 with the older ones?
Q12. Difference between render and redirect?
Sol: render example: render :action, render :partial etc.
redirect example: redirect_to :controller => ‘users’, :action => ‘new’
Q13. How to use sql db or mysql db. without defining it in the database.yml
Sol. http://stuff.lilleaas.net/active_record_anywhere
Q14. What are helpers and how to use helpers in ROR?
Sol. Helpers (“view 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 you to keep the programming out of your views. The purpose of a helper is to simplify the view. It’s best if the view file (RHTML/RXML) is short and sweet, so you can see the structure of the output.
Q15. What is Active Record?
Sol. Active Record are like Object Relational Mapping(ORM), where classes are mapped to table and objects are mapped to colums in the table
Q16. Ruby Supports Single Inheritence/Multiple Inheritence or Both?
Sol. Ruby Supports only Single Inheritnece
Q17. How many types of callbacks available in ROR?
Sol. * (-) save
* (-) valid
* (1) before_validation
* (2) before_validation_on_create
* (-) validate
* (-) validate_on_create
* (3) after_validation
* (4) after_validation_on_create
* (5) before_save
* (6) before_create
* (-) create
* (7) after_create
* (8) after_save
Q18. Suppose in one of my method I am updating the attributes of table, in my model I have defined after_create do X, and after_save do Y. Which method will be called?
Q19. How to use two database into a Single Application?
Sol. http://magicmodels.rubyforge.org/magic_multi_connections/, According to this link : ActiveRecord models are allowed one connection to a database at a time, per class. Ruby on Rails sets up the default connection based on your database.yml configuration to automatically select development, test or production.
But, what if you want to access two or more databases – have 2+ connections open – at the same time. ActiveRecord requires that you subclass ActiveRecord::Base.
That prevents you doing migrations from one database to another. It prevents you using one set of model classes on two or more databases with the same schema.
Magic Multi-Connections allows you to write your models once, and use them for multiple Rails databases at the same time. How? Using magical namespacing.

To do this :
[A] sudo gem install magic_multi_connections
[B] require ‘magic_multi_connections’
Add the following to the bottom of your environment.rb file
You can also find examples on this link : http://magicmodels.rubyforge.org/magic_multi_connections/
“Updated Set of Questions for Rails 3”
Q20. Tell us the changes between the Rails version 2 and 3?
Sol. *  (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
Q21. What is bundler?
Sol: Bundler is a new concept introduced in Rails3, which helps to you manage your gems for the application. After specifying gems in your Gemfile, you need to do a bundle install. If the gem is available in the system, bundle will use that else it will pick up from the rubygems.org.
Q22. What is the Newest approach for find(:all) in Rails 3?
Sol: Model.where(:activated => true)
Q23. What is Gemfile and Gemfile.lock?
Ruby Interview Questions :
Q1. What is the Notation used for denoting class variables in Ruby?
Q2. What is the use of Destructive Method?
Q3. What is the use of load and require in Ruby?
Q4. What is the use of Global Variable in Ruby?
Q5. How does nil and false differ?
Q6. How is visibility of methods change in Ruby?
Q7. What is a Class Instance Variable
Q8. What are the rules and conventions to be followed in Ruby for naming a method?
Q9. What is the use of Super?
Q10. How is class method defined in Ruby?
Q11. What are the Operators available in Ruby?
Q12. What are the looping structure available in Ruby?
Q13. What is the scope of local variable?
Q14. What are the OOP supported by Ruby?
Q15. If Ruby over PHP, Why?
Q16. Garbage collection in Ruby?
Q17. Environment Variables in Ruby?
Q18. What are Float, Dig and Max?
Q19. What is Ruby Code blocks?
Q20. What kind of conditions ruby support?
Q21. Difference between puts and print
Some More Questions are here:
Q1. What is Agile methodology? What are their Processes?
Q2. Is there any technology apart from agile which we can use?
Q3. What are the servers supported by ruby on rails application?
Q4. What is new in Rails 3.0?
Q5. What is Meta-programming? How you are using it inside your rails application?
Q6. What is has_many?
Ans. It is a way of defining relationships among models. Correct, and Do you guys really know has_many is also an example of Meta-programming? Wondering, How?
Q7. What is TDD and BDD?
Hint: Test-Driven-Development and Behavior-Driven-Development
Q8. What is rspec, cucumber and Watir? And what it has to do with TDD and BDD?
More Questions and Answers of this will be published very soon  So stay in touch.. I will keep you updating.. if you have some questions please reply




1.Difference between html.erb & rhtml
It's just a change of philosophy between Rails 1 and Rails 2.Before Rails 2, we had file.rhtml, file.rxml and file.rjs.In Rails 2.0, that changed to file.content_type.template_engine. So with file.html.erb,the content type is html and the template engine is ERB. rxml is now xml.builder and rjs should now (mostly) be js.rjs.
2.What is dynamic database

3.Difference between dynamic hasfinder and hasfinder
Most common operations in many applications is to simply query based on one or two columns, Rails has an easy and effective way to do these queries
without having to resort to the conditions parameter of find.Dynamic finder methods begin with find_by_name or find_all_by_name, indicating whether you want a single value or array of results returned. The semantics are simi-
lar to calling find with the :first versus the :all option.

>> City.find_by_name("Hackensack")
=> # "Hackensack", "latitude" =>"40.8858330000", "id" => "15942", "longitude" => "-74.0438890000","state" => "NJ" }>
>> City.find_all_by_name("Atlanta").collect(&:state)
=> ["GA", "MI", "TX"]

It's also possible to use multiple attributes in the same find by separating them with "and", so you get finders like Person.find_by_user_name_and_password or
even Payment.find_by_purchaser_and_state_and_country.

Has finder or named_scope is an extension to ActiveRecord that makes it easy to create custom finder and count methods on your ActiveRecord models. Read all about it at
Has finder
4.What is ORM
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming language.Active Record is the object-relational mapping (ORM) layer supplied with Rails.Active Record closely follows the standard ORM model,ORM libraries map database tables to classes,
rows to objects, and columns to object attributes.
5.Tell briefly about Active Record
Read all about it at Active Record

6.What is Associations
Active Record associations declaratively express relationships between model classes. The power and readability of the Associations API is an important part of what makes working with Rails so special.Associations typically appear as methods on ActiveRecord model objects.

Associations are a set of macro-like class methods for tying objects together through foreign keys.Each macro adds a number of methods to the class which are specialized according to the collection or association symbol and the options hash. It works much the same way as Ruby‘s own attr* methods
7.What do you mean by polymorphic associations
Polymorphic relationships allow you to have a single model that can be associated to an arbitrary number of other model types.
8.What is HABTM
A has_and_belongs_to_many association creates a direct many-to-many connection with another model, with no intervening model.
9.In HABTM, how will be the join table naming convention(For example Models User and Role)
Join table will be as per alphabetical order, then the join table will be named as roles_user
10.What is meta programming

11.What is Rspec

12.Tell briefly about RESTFUL Architecture

13.Difference between map.resources and map.resource

14.What is a block

15.Define Lambda & Proc

16.Difference between Lambda & Proc

17.Three levels of protection in ruby

18.Difference between protected method and private method

19.What is attr_accessor, attr_protected

20.How a website is working in Rails application

21.What is sessions and cookies

22.How sessions are storing

23.What is gem and difference between gem and plugin

24.What is TDD

25.What are callbacks

26.Why ruby is called as dynamic language

27.What is namespace

28.What is left join and outer join

29.How many engines mysql is having

30.What are called modules and what is the use of lib folder
Modules are a way of grouping together methods, classes, and constants. Modules give you two major benefits.
1. Modules provide a namespace and prevent name clashes.
2. Modules support the mixin facility.

Lib directory holds application code that doesn’t fit neatly into a model,
view, or controller.The lib directory is also a good place to put code that’s shared among models,views, or controllers.If the file is in the lib directory
itself, you require it directly by name.
31.How to provide grant permission for mysql
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost' IDENTIFIED BY 'my_password' WITH GRANT OPTION;
32.Difference between single quote and double quote in ruby
Single-quoted strings are treated as literals; double-quoted strings are interpolated.Single quotes will print the value whereas double quotes will execute it.
For example
>> r = 42
=> 42
>> "#{r}"
=> "42"
>> '#{r}'
=> "\#{r}"
33.Why ruby?
Most enterprise software running today was written in languages such as COBOL, C/C++, and Java. Because of its distributed nature, enterprise software often makes it easy to use new tools and programminglanguages. When you have to create a small standalone application one that only relies upon an existing database, SOAP service, or LDAP repository—it almost doesn’t seem to matter if you were to write it in C++, Java, or Ruby. But if you look into it more deeply, dynamic languages such as Perl, Python, and Ruby have many of advantages, especially in enterprise environments:
• They are interpreted and do not need a compile phase, which increases development speed tremendously. After editing your program you can see the results of your changes immediately.
• Enterprise software is about munging data. Dynamic languages are designed to handle data, and include high-level data types such as hashes.
• Memory management is dealt with by the language. This is a great advantage over languages such as C++ where you have to specify the length of each string you read from a database. Dynamic languages prevent waste and result in more concise, more robust,and more secure software.
• Software written in dynamic languages is installed as source code,so you always know exactly which version is currently running on your production system. Gone are the days when you had to guess if a certain binary executable is the right one.

Questions
What are the differences betweeen Rails 2.x and Rails 3 CTS  2  548   iam new to the ruby on rails. suggest me some pdf and online books for ruby and rails  0  136   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?  1  310   am new to ruby. tell me one thing. i can view my project on browser when i write "ruby script/server". otherwise i cant view my project on localhost. what i have to do to view my project always on browser? pls help  3  809   Is Ruby is a Scripting Language or Compiled Language?  3  2365   How are Model views and controllers related?  3  1979   What is the functionality of Model views and controllers  2  985   What is the architecture of Model views and controllers  0  367   What is the difference between sessions and flash?  2  1827   What are filters? and how many types of filters are there in ruby  2  2124   let me know what is ruby software and where and when it is usefull. Is it usefull to data base developer, if yes...where? thank you  1  846   I would like to know about ruby on rails.I want to know.how will be the future for ruby on rails.please tell me. TCS  9  2351   difference between form_for and form_tag  2  7187   Why do we use request.xhr? in rails  2  9273   what the difference between static scaffolding and Dynamic scaffolding?



1.1 What is Ruby?
Ruby is a pure object-oriented programming language with a super clean syntax that makes programming elegant and fun. Ruby successfully combines Smalltalk's conceptual elegance, Python's ease of use and learning, and Perl's pragmatism. Ruby originated in Japan in the early 1990s, and has started to become popular worldwide in the past few years as more English language books and documentation have become available.
1.2 What is Rails?
Rails is an open source Ruby framework for developing database-backed web applications. What's special about that? There are dozens of frameworks out there and most of them have been around much longer than Rails. Why should you care about yet another framework? What would you think if I told you that you could develop a web application at least ten times faster with Rails than you could with a typical Java framework? You can--without making any sacrifices in the quality of your application! How is this possible? Part of the answer is in the Ruby programming language. Many things that are very simple to do in Ruby are not even possible in most other languages. Rails takes full advantage of this. The rest of the answer is in two of Rail's guiding principles: less software and convention over configuration. Less software means you write fewer lines of code to implement your application. Keeping your code small means faster development and fewer bugs, which makes your code easier to understand, maintain, and enhance. Very shortly, you will see how Rails cuts your code burden. Convention over configuration means an end to verbose XML configuration files--there aren't any in Rails! Instead of configuration files, a Rails application uses a few simple programming conventions that allow it to figure out everything through reflection and discovery. Your application code and your running database already contain everything that Rails needs to know!

1.3 How to capitalize UTF8 string without downcasingWhat is the best way to capitalize the first character of a UTF8 string? String#capitalize downcases the rest of the string which is unacceptable since there can be capitals in the middle of the string. ("see New York".capitalize => "See new york"). Just picking off the first byte and capitalizing that is also not an option since the first character can be a multibyte UTF-8 character. The only thing I can think of so far is either using Ruby 1.9 or the the Rails multibyte Chars library to split off the first character and then capitalize that and join it back together. Surely there must be a better way for such a common problem? 1.4 What is the naming conventions for methods that return a boolean result?Methods that return a boolean result are typically named with a ending question mark. For example: def active? return true #just always returning true end 1.5 What are the object-oriented programming features supported by Ruby?Classes,Objects,Inheritance,Singleton methods,polymorphism(accomplished by over riding and overloading) are some oo concepts supported by ruby. ...1.6 What are the operating systems supported by Ruby?Windows and linux operating systems are supported by the Ruby1.7 Whats the difference between symbol and string?  Symbol refers to the same memory location where string generates a new id every time for eg.
STRING
irb(main):019:0> "ruby".object_id
=> 24095860
irb(main):020:0> "ruby".object_id
=> 24092310
irb(main):021:0> "ruby".object_id
=> 24088760
irb(main):022:0>
SYMBOL
irb(main):022:0> :ruby.object_id
=> 102978
irb(main):023:0> :ruby.object_id
=> 102978
irb(main):024:0> :ruby.object_id
=> 102978
irb(main):025:0> :ruby.object_id
=> 102978
irb(main):026:0>
1.8 How do you comment out a block of code? Use =begin and =end. =begin def
my_commented_out_method end =end
You could use successive # signs, but that's just tedious: # # def my commented_out_method # end #1.9 How would you create a new ruby rail application?To create a new ruby rail application rails my_app cd my_app1.10 What is the difference between nil and false in ruby?False is a boolean datatype Nil is not a data type 1.11 What two delimiters are used for blocks?Curly braces {...} and "do"..."end" Bonus: coding convention is to use curly braces if the code will fit on one line and "do"..."end" syntax if the block contains multiple lines.1.12 What is the naming conventions for methods that return a boolean result?Methods that return a boolean result are typically named with a ending question mark. For example: def active? return true #just always returning true end1.13 Explain about the programming language ruby?Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable. Oh, I need to mention, it's totally free, which means not only free of charge, but also freedom to use, copy, modify, and distribute it.
Features of Ruby
* Ruby has simple syntax, partially inspired by Eiffel and Ada.
* Ruby has exception handling features, like Java or Python, to make it easy to handle errors.
* Ruby's operators are syntax sugar for the methods. You can redefine them easily.
* Ruby is a complete, full, pure object oriented language: OOL. This means all data in Ruby is an object, in the sense of Smalltalk: no exceptions. Example: In Ruby, the number 1 is an instance of class Fixnum.
* Ruby's OO is carefully designed to be both complete and open for improvements. Example: Ruby has the ability to add methods to a class, or even to an instance during runtime. So, if needed, an instance of one class *can* behave differently from other instances of the same class.
* Ruby features single inheritance only, *on purpose*. But Ruby knows the concept of modules (called Categories in Objective-C). Modules are collections of methods. Every class can import a module and so gets all its methods for free. Some of us think that this is a much clearer way than multiple inheritance, which is complex, and not used very often compared with single inheritance (don't count C++ here, as it has often no other choice due to strong type checking!).
* Ruby features true closures. Not just unnamed function, but with present variable bindings.
* Ruby features blocks in its syntax (code surrounded by '{' ... '}' or 'do' ... 'end'). These blocks can be passed to methods, or converted into closures.
* Ruby features a true mark-and-sweep garbage collector. It works with all Ruby objects. You don't have to care about maintaining reference counts in extension libraries. This is better for your health. ;-)
* Writing C extensions in Ruby is easier than in Perl or Python, due partly to the garbage collector, and partly to the fine extension API. SWIG interface is also available.
* Integers in Ruby can (and should) be used without counting their internal representation. There *are* small integers (instances of class Fixnum) and large integers (Bignum), but you need not worry over which one is used currently. If a value is small enough, an integer is a Fixnum, otherwise it is a Bignum. Conversion occurs automatically.
* Ruby needs no variable declarations. It uses simple naming conventions to denote the scope of variables. Examples: simple 'var' = local variable, '@var' = instance variable, '$var' = global variable. So it is also not necessary to use a tiresome 'self.' prepended to every instance member.
* Ruby can load extension libraries dynamically if an OS allows.
* Ruby features OS independent threading. Thus, for all platforms on which Ruby runs, you also have multithreading, regardless of if the OS supports it or not, even on MS-DOS! ;-)
* Ruby is highly portable: it is developed mostly on Linux, but works on many types of UNIX, DOS, Windows 95/98/Me/NT/2000/XP, MacOS, BeOS, OS/2, etc.
1.14 Why Ruby on Rails?1)for fast developing websites
2)convention over configuration
3)scaffolding
4)pure Object oriented concepts
5)less coding
6)easy understanding of coding
7)follows MVC architecture
8)using library and gem files
  Re: What is the functionality of Model views and controllers Answer
# 1
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.
 
Is This Answer Correct ?  
11 Yes
0 No
0
Guest
    Re: What is the functionality of Model views and controllers Answer
# 2
MVC is a pattern for the architecture of a software
application. It separates an application into the following
three components:

    * models, for handling data and business logic
    * controllers, for handling the user interface and
application logic
    * views, for handling graphical user interface objects
and presentation logic

This separation results in user requests being processed as
follows:

   1. The browser, on the client, sends a request for a page
to the controller on the server.

   2. The controller retrieves the data it needs from the
model in order to respond to the request.

   3. The controller renders the page and sends it to the view.

   4. The view sends the page back to the client for the
browser to display.
Re: What are the differences betweeen Rails 2.x and Rails 3 Answer
# 1
some functionality difference ...
 
Is This Answer Correct ?  
2 Yes
3 No
0
Kuna
    Re: What are the differences betweeen Rails 2.x and Rails 3 Answer
# 2
some functionality changers..
 ex- in rail2.x
     <%= link_to_remote ‘Show’, :url => post %>

 ex in rail3.x
    <%= link_to ‘Show’, post, :remote => true %>


etc..
Re: Is Ruby is a Scripting Language or Compiled Language? Answer
# 1
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.
 
Is This Answer Correct ?  
50 Yes
0 No
4
Abhi2810
    Re: Is Ruby is a Scripting Language or Compiled Language? Answer
# 2
ruby is scripting language
  Re: How are Model views and controllers related? Answer
# 1
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 ...
 
Is This Answer Correct ?  
35 Yes
4 No
4
Ganesh Mohan
    Re: How are Model views and controllers related? Answer
# 2
models ,views and controllers are related side by side.data
if sent to models is first worked upon its database
operations (CRUD) ,then the data is sent to view where its
templates are designed then finally data is sent to
controllers where data is processed and organised...
 
Is This Answer Correct ?  
3 Yes
17 No
0
Lubna
 

      Re: How are Model views and controllers related? Answer
# 3
MVC is a pattern for the architecture of a software
application. It separates an application into the following
three components:

    * models, for handling data and business logic
    * controllers, for handling the user interface and
application logic
    * views, for handling graphical user interface objects
and presentation logic

This separation results in user requests being processed as
follows:

   1. The browser, on the client, sends a request for a page
to the controller on the server.

   2. The controller retrieves the data it needs from the
model in order to respond to the request.

   3. The controller renders the page and sends it to the view.

   4. The view sends the page back to the client for the
browser to display.
Re: What is the difference between sessions and flash? Answer
# 1
Session is for the application i.e If user logs in the
session will be applied for the user.
Flash is valid from one request to other i.e if the page is
redirected from one page to other,its valid in within this
request.
 
Is This Answer Correct ?  
17 Yes
4 No
0
Milind Kanchan
    Re: What is the difference between sessions and flash? Answer
# 2
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 messsages in view pages...
  Re: What are filters? and how many types of filters are there in ruby Answer
# 1
basically filters are used to run some code or skip some
code  before executing particular action.It is used in
controller.say we want to check authenticity before we
executing some action or skip checking authenticity before
some action which automatically is configured to check the
authenticity.We can do it by before_filter :somemethod or
skip_before_filter :someaction inside my controller.
 
Is This Answer Correct ?  
18 Yes
1 No
0
Sanjib
    Re: What are filters? and how many types of filters are there in ruby Answer
# 2
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
  Re: let me know what is ruby software and where and when it is usefull. Is it usefull to data base developer, if yes...where? thank you Answer
# 1
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
  Re: difference between form_for and form_tag Answer
# 1
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 -%>
 
Is This Answer Correct ?  
41 Yes
1 No
4
Arpita Patel
    Re: difference between form_for and form_tag Answer
# 2
The difference between the two is that form_tag just outputs
a <form>tag , It doesn't relies on activerecord object

and form_for gives you a means of accessing some wrapped object.
  Re: Why do we use request.xhr? in rails Answer
# 1
request.xhr? indicates the controller has
received an ajax request. It returns true or false
 
Is This Answer Correct ?  
38 Yes
5 No
3
Surekha Matte
    Re: Why do we use request.xhr? in rails Answer
# 2
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).
  Re: what the difference between static scaffolding and Dynamic scaffolding? Answer
# 1
Hi,

Static scaffolding is present in rails 1.0 version with the
comand
"ruby script/server geterate scaffold Product Admin".
Here, Product is model and Admin is controller.So it (Rails
1.0)automatically generates the table column defined in
products table
CONCLUSION:SCAFFOLDING IN RAILS 1.0 TAKES TWO PARAMETERS
1.MODEL
2.CONTROLLER

While in dynamic scaffolding u need to create model and
controller one by one
 
Is This Answer Correct ?  
12 Yes
4 No
1
Vikrant Chaudhari
    Re: what the difference between static scaffolding and Dynamic scaffolding? Answer
# 2
dynamic scaffolding is

when you give the line scaffold :model_name in your
controller ruby will automatically generate all the
appropriate data interfaces at runtime.

Comments

  1. Ruby Interview Questions and Answers
    http://allinterviewquestionsandanswerspdf.blogspot.in/2016/06/top-26-ruby-interview-questions-and.html

    ReplyDelete
  2. Searching for the Ultimate Dating Website? Join to find your perfect date.

    ReplyDelete

Post a Comment

Popular posts from this blog

Get the Current url in ruby on rails

request.refererrequest.fullpathrequest.fullpath.split("?")[0]request.referer or request.env['HTTP_REFERER'] your controller to get the referer url. 

--------------------
request.original_url
request.url
request.host_with_port
<link rel="canonical" href="<%= request.url %>" />
<%=request.path%>
How can I get the current absolute URL in my Ruby on Rails view?
The request.request_uri only returns the relative URL.
request.env['REQUEST_URI']

 For Rails 3.2 or Rails 4 you should use request.original_url to get the current URL. More detail.

For Rails 3: You want "#{request.protocol}#{request.host_with_port}#{request.fullpath}", since request.url is now deprecated.

For Rails 2: You want request.url instead of request.request_uri. This combines the protocol (usually http://) with the host, and request_uri to give you the full address

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).?

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).) In rails?


1)change the gemfile in mysql version
 gem 'mysql2'

2)Change to mysql2 version
 gem 'mysql2','0.3.20'

Active Scaffold : Add radio buttons to your form ruby on rails ?

Active Scaffold : Add radio buttons to your form ruby on rails ?

The way to add radio buttons to your active scaffold create/update from is as shown below

#Controller

class UsersController < ApplicationController
active_scaffold :user do |config|
config.label = “Users”
config.columns = [:name, :gender]
config.columns[:gender].form_ui = :radio
config.columns[:gender].options[:options] = [['Male', '1'], ['Female','2']]
end
end