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 3 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…