1. What Is Rails?
1. Rails is a extremely productive web-application framework written in Ruby language by David Hansson.
2. Rails are an open source Ruby framework for developing database-backend web applications.
3. Rails include everything needed to create a database-driven web application using the Model-View-Controller (MVC) pattern.
2. What Are The Various Components Of Rail?
1. Action Pack: Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch. The “VC” part of “MVC”.
Action Controller: Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action.
Services provided by Action Controller include session management, template rendering, and redirect management.
Action View: Action View manages the views of your Rails application. It can create both HTML and XML output by default.
Action View manages rendering templates, including nested and partial templates, and includes built-in AJAX support.
Action Dispatch: Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application. Rack applications are a more advanced topic and are covered in a separate guide called Rails on Rack.
2. Action Mailer: Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.
3. Active Model: Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.
4. Active Record: 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.
5. Active Resource: Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.
6. Active Support: Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.
3. Explain About Restful Architecture?
RESTful: REST stands for Representational State Transfer. REST is an architecture for designing both web applications and application programming interfaces (API’s), that’s uses HTTP.
RESTful interface means clean URLs, less code, CRUD interface. CRUD means Create-READ-UPDATE-DESTROY. In REST, they add 2 new verbs, i.e, PUT, DELETE.
4. Why Ruby On Rails?
There are lot of advantages of using ruby on rails.
1. DRY Principal( Don’t Repeat Yourself): It is a principle of software development aimed at reducing repetition of code. “Every piece of code must have a single, unambiguous representation within a system”
2. Convention over Configuration: Most web development framework for .NET or Java force you to write pages of configuration code. If you follow suggested naming conventions, Rails doesn’t need much configuration.
3. Gems and Plugins: RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing ruby programs and library.
Plugins: A Rails plugin is either an extension or a modification of the core framework. It provides a way for developers to share bleeding-edge ideas without hurting the stable code base. We need to decide if our plugin will be potentially shared across different Rails applications.
4. Scaffolding: Scaffolding is a meta-programming method of building database-backend software application. It is a technique supported by MVC frameworks, in which programmer may write a specification, that describes how the application database may be used. There are two type of scaffolding:
-static: Static scaffolding takes 2 parameter i.e your controller name and model name.
-dynamic: In dynamic scaffolding you have to define controller and model one by one.
5. Rack Support: Rake is a software task management tool. It allows you to specify tasks and describe dependencies as well as to group tasks in a namespace.
6. Metaprogramming: Metaprogramming techniques use programs to write programs.
7. Bundler: Bundler is a new concept introduced in Rails 3, which helps you to manage your gems for application. After specifying gem file, you need to do a bundle install.
8. Rest Support.
9. Action Mailer
5. What Do You Mean By Render And Redirect_to?
render causes rails to generate a response whose content is provided by rendering one of your templates. Means, it will direct goes to view page.
redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.
6. What Is Orm In Rails?
ORM tends for Object-Relationship-Model, where Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.
7. How Many Types Of Associations Relationships Does A Model Have?
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.
8. What Are Helpers And How To Use Helpers In Ror?
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.
9. What Are Filters?
Filters are methods that run “before”, “after” or “around” a controller action. Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application.
10. What Is Mvc? And How It Works?
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.
11. What Is Session And Cookies?
Session is used to store user information on the server side. Maximum size is 4 kb. Cookies are used to store information on the browser side or we can say client side.
12. What Is Request.xhr?
A request.xhr tells the controller that the new Ajax request has come, It always return Boolean values (TRUE or FALSE)
13. What Things We Can Define In The Model?
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
14. How Many Types Of Callbacks Available In Ror?
1. before_validation
2. before_validation_on_create
3. validate_on_create
4. after_validation
5. after_validation_on_create
6. before_save
7. before_create
8. after_create
9. after_save
15. How To Serialize Data With Yaml?
YAML is a straight forward machine parsable data serialization format, designed for human readability and interaction with scripting language such as Perl and Python.
YAML is optimized for data serialization, formatted dumping, configuration files, log files, internet messaging and filtering.
16. How To Use Two Databases Into A Single Application?
magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time.
sudo gem install magic_multi_connection. After installing this gem, just add this line at bottom of your environment.rb require “magic_multi_connection”
17. What Are The Various Changes Between The Rails Version 2 And 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. HTML5 support
18. What Is Tdd And Bdd?
TDD stands for Test-Driven-Development and BDD stands for Behavior-Driven-Development.
19. What Are The Servers Supported By Ruby On Rails?
RoR was generally preferred over WEBrick server at the time of writing, but it can also be run by:
Lighttpd (pronounced ‘lighty’) is an open-source web server more optimized for speed-critical environments.
Abyss Web Server- is a compact web server available for windows, Mac osX and Linux operating system. Apache and nginx
20. What Do You Mean By Naming Convention In Rails.
Variables: Variables are named where all letters are lowercase and words are separated by underscores. E.g: total, order_amount.
Class and Module: Classes and modules uses MixedCase and have no underscores, each word starts with a uppercase letter. Eg: InvoiceItem
Database Table: Table name have all lowercase letters and underscores between words, also all table names to be plural. Eg: invoice_items, orders etc
Model: The model is named using the class naming convention of unbroken MixedCase and always the singular of the table name.
For eg: table name is might be orders, the model name would be Order. Rails will then look for the class definition in a file called order.rb in /app/model directory. If the model class name has multiple capitalized words, the table name is assumed to have underscores between these words.
Controller: controller class names are pluralized, such that Orders Controller would be the controller class for the orders table. Rails will then look for the class definition in a file called orders_controlles.rb in the /app/controller directory.
21. What Is The Log That Has To Seen To Check For An Error In Ruby Rails?
Rails will report errors from Apache in log/apache.log and errors from the ruby code in log/development.log. If you having a problem, do have a look at what these log are saying.
22. How You Run Your Rails Application Without Creating Databases?
You can run your application by uncommenting the line in environment.rb
path=> rootpath conf/environment.rb
config.frameworks-=[action_web_service,:action_mailer,:active_record
23. How To Use Sql Db Or Mysql Db Without Defining It In The Database.yml?
You can use ActiveRecord anywhere
require “rubygems”
require “active_record”
ActiveRecord::Base.establish_connection({ :adapter=> ‘postgresql’, :user=>’foo’, :password=> ‘abc’, :database => ’whatever’})
24. Get And Post Method?
GET is basically for just getting (retrieving) data, whereas POST may involve anything, like storing or updating data, or ordering a product, or sending E-mail.
25. What Is The Difference Between Static And Dynamic Scaffolding?
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.
26. How Many Types Of Relationships Does A Model Has?
1. has_one
2. belongs_to
3. has_many
4. has_many :through
27. Difference Between Render And Redirect?
render example: render :action, render :partial etc. redirect example: redirect_to :controller => ‘users’, :action => ‘new’
28. What Is Active Record?
Active Record are like Object Relational Mapping(ORM), where classes are mapped to table and objects are mapped to columns in the table.
29. Ruby Supports Single Inheritance/multiple Inheritance Or Both?
Ruby Supports only Single Inheritance
30. What Is Bundler?
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.
31. What Is The Newest Approach For Find(:all) In Rails 3?
Model.where(:activated => true)
32. What Is The Role Of Mvc Architecture In Ruby On Rails?
MVC (Model-View-Controller) is the architecture that provides flexibility and scalability of the applications.
It is almost having the same concept in any other language like PHP, Perl or Python. It is one of the major used architecture involved today due to its simplicity.
Controller is the main part in this kind of architecture where it handles the request that is coming from another controller.
Controller contacts the view and passes on the request to the view and it also interacts with the model to define the type of request.
Model is responsible for interacting with the database and provides the responses to the controller.
Controller takes the response and gives the response in the output form to the user that has made the request.
33. What Are The Components Defined In The Model From Mvc Architecture?
The components involved in defining the model are as follows:
Validations: this is one of the very essential components and it defines the validations that are being put up on the input type of stream like validate_presence_of, format_of, etc.
Relationship: this is another type of component that describe the relationship between different types of components and it shows the relationship in the form of has_one, has_many, etc.
Callbacks: this is essential when it comes to respond after the failure and it allows the application to have certain functionality during failure. This can be given as before_save, after_save, etc.
Validation group settings: allow users to define the installed plugin settings.
Active record association relationship: allows current records to be actively having the relationship between one another.
34. Choosing Between Belongs_to And Has_one?
If you want to set up a one-to-one relationship between two models, you'll need to add belongs_to to one, and has_one to the other. How do you know which is which?
The distinction is in where you place the foreign key (it goes on the table for the class declaring the belongs_to association), but you should give some thought to the actual meaning of the data as well. The has_one relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier.
35. Render Vs. Redirect_to In Ruby On Rails ?
render will render a particular view using the instance variables available in the action.
For example if a render was used for the new action, when a user goes to /new, the new action in the controller is called, instance variables are created and then passed to the new view. Rails creates the html for that view and returns it back to the user's browser. This is what you would consider a normal page load.
redirect_to will send a redirect to the user’s browser telling it to re-request a new URL as 302 redirect response. Then the browser will send a new request to that URL and it will go through the action for that URL, oblivious to the fact that it was redirected to. None of the variables created in the action that caused the redirect will be available to the redirected view. This is what happens when you click on ‘Create’ in a form and the object is created and you’re redirected to the edit view for that object.
36. What Is The Difference Between Save And Save?
Save! performs all validations and callbacks. If any validation returns false, save! throws an error and canceles the save.
Save does not throw any error in the case above, but canceles the save. Also, the validators can be bypassed.
37. What Is The Difference Between Delete And Destroy ?
The delete method essentially deletes a row (or an array of rows) from the database. Destroy on the other hand allows for a few more options. First, it will check any callbacks such as before_delete, or any dependencies that we specify in our model. Next, it will keep the object that just got deleted in memory; this allows us to leave a message saying something like “ 'Object_name' has been deleted.” Lastly, and most importantly, it will also delete any child objects associated with that object!
38. What Are Filters? And How Many Types Of Filters Are There In Ruby ?
Filters are methods that are run before, after or "around" a controller action.
Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application.
Filter can take one of three forms: method reference (symbol), external class, or inline method (proc).
after_filter
append_after_filter
append_around_filter
append_before_filter
around_filter
before_filter
filter_chain
prepend_after_filter
prepend_around_filter
prepend_before_filter
skip_after_filter
skip_before_filter
skip_filter
39. What Is The Flash?
The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash.
flash is a object of Actiondispatch class.
40. Difference Between Argument And Parameter In Ruby On Rails ?
A parameter represents a value that the method expects you to pass when you call it.
An argument represents the value you pass to a method parameter when you call the method. The calling code supplies the arguments when it calls the method.
In simple words, parameters appear in method definitions; arguments appear in method calls.
For example, in below method, variables param1 and param2 are the parameters
def foo_method(param1, param2):
.......
end
while calling the method, arg1 and arg2 are the arguments
foo_method(arg1, arg2)
41. What Is The Difference Between Symbol And String ?
The symbol in Ruby on rails act the same way as the string but the difference is in their behaviors that are opposite to each other.
The difference remains in the object_id, memory and process time for both of them when used together at one time.
Strings are considered as mutable objects. Whereas, symbols, belongs to the category ofimmutable.
Strings objects are mutable so that it takes only the assignments to change the object information. Whereas, information of, immutable objects gets overwritten.
-String objects are written like
o "string object jack".object_id #=>2250 or
o "string object jack".to_sym.object_id #=> 2260, and
o "string object jack". to_s_object_id #=> 2270
Symbols are used to show the values for the actions like equality or non-equality to test the symbols faster then the string values.
42. Write A Program To Show The Functionality Of Request.xhr In Ruby On Rails ?
Request from the request.xhr displays the controller that manages and creates the new AJAX that is being handled by the new controller.
The Boolean values that are retured should generate only TRUE or FALSE. These values are used to be inserted for this purpose.
The request.xhr is being shown in a program shown below as:
def create
return unless request.xhr?
@imageable = find_imageable
@image = @imageable.images.build(params[:imageable])
@image.save
render :layout => false
end
43. What Are The Different Components Of Rails ?
The components used in Rails are as follows:
Action Controller: it is the component that manages all other controllers and process the incoming request to the Rails application.
It extracts the parameters and dispatches the response when an action is performed on the application.
It provides services like session management, template rendering and redirect management.
Action View: it manages the views of the Rails application and it creates the output in both HTML and XML format.
It also provides the management of the templates and gives the AJAX support that is being used with the application.
Active Record: It provides the base platform for the models and gets used in the Rails application. It provides the database independence, CRUID functionality, search capability and setting the relationship between different models.
Action Mailer: It is a framework that provides email services to build the platform on which flexible templates can be implemented.
44. What Is The Purpose Of Load, Auto_load, And Require_relative In Ruby ?
Load allows the process or a method to be loaded in the memory and it actually processes the execution of the program used in a separate file.
It includes the classes, modules, methods and other files that executes in the current scope that is being defined. It performs the inclusion operation and reprocesses the whole code every time the load is being called.
require is same as load but it loads code only once on first time.
Auto_load: this initiates the method that is in hat file and allows the interpreter to call the method.
require_relative: allows the loading to take place of the local folders and files.
45. What Is A Proc ?
Everyone usually confuses procs with blocks, but the strongest rubyist can grok the true meaning of the question.
Essentially, Procs are anonymous methods (or nameless functions) containing code. They can be placed inside a variable and passed around like any other object or scalar value. They are created by Proc.new, lambda, and blocks (invoked by the yield keyword).
Blocks are very handy and syntactically simple, however we may want to have many different blocks at our disposal and use them multiple times. As such, passing the same block again and again would require us to repeat ourself. However, as Ruby is fully object-oriented, this can be handled quite cleanly by saving reusable code as an object itself. This reusable code is called aProc (short for procedure). The only difference between blocks and Procs is that a block is a Proc that cannot be saved, and as such, is a one time use solution.
46. What Is Unit Testing (in Classical Terms)? What Is The Primary Technique When Writing A Test ?
Unit testing, simply put, is testing methods -- the smallest unit in object-oriented programming. Strong candidates will argue that it allows a developer to flesh out their API before it's consumed by other systems in the application.
The primary way to achieve this is to assert that the actual result of the method matches an expected result.
47. What Is The Difference Between Nil And False In Ruby ?
False is a boolean datatype, Nil is not a data type it have object_id 4.
• What Are The Looping Structures Available In Ruby ?
• for..in
• untill..end
• while..end
do..end
Note: You can also use each to iterate a array as loop not exactly like loop
48. How Is Visibility Of Methods Changed In Ruby (encapsulation) ?
By applying the access modifier : Public , Private and Protected access Modifier
49. Dynamic Finders ?
For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called first_name on your Client model for example, you getfind_by_first_name and find_all_by_first_name for free from Active Record. If you have a locked field on the Client model, you also get find_by_locked and find_all_by_lockedmethods.
You can also use find_last_by_* methods which will find the last record matching your argument.
You can specify an exclamation point (!) on the end of the dynamic finders to get them to raise an ActiveRecord::RecordNotFound error if they do not return any records, like Client.find_by_name!("Ryan")
If you want to find both by name and locked, you can chain these finders together by simply typing "and" between the fields. For example, Client.find_by_first_name_and_locked("Ryan", true).
50. Finding By Sql ?
If you'd like to use your own SQL to find records in a table you can use find_by_sql. The find_by_sql method will return an array of objects even if the underlying query returns just a single record.
For example you could run this query:
Client.find_by_sql("SELECT * FROM clients
INNER JOIN orders ON clients.id = orders.client_id ORDER clients.created_at desc")
find_by_sql provides you with a simple way of making custom calls to the database and retrieving instantiated objects.
51.Is Rails scalable?
A.Yes Rails gives you complete freedom to use all traditional means of scaling an application. Things like memcached, caching full pages, caching fragments are all supported.
52.How can you safeguard a rails application from SQL injection attack?
A.Rails already has the logic built into it to prevent SQL injection attacks if you follow the right syntax.
53.How can you secure a rails application?
A.Rails has a lot of in-built capabilities to deal with common web-security issues. Like : SQL Injection, Cross-Site , Session fixation and Session hijacking, Captcha
54.Can you tell me a few good community resources for Rails?
A.Stackoverflow, Github, various Meetup groups.
55.Where would you reach out to get the community to answer your questions?
A.Stackoverflow and meetup groups.
56.In which Programming language was Ruby written?
A.Ruby was written in C language and Ruby on Rails written in Ruby
57.How many types of relationships does a Model has?
A.has_one, belongs_to, has_many and has_many :through
58.What is Ruby Gems?
A.Ruby Gem is a software package, commonly called a "gem". Gem contains a packaged Ruby application or library. The Ruby Gems software itself allows you to easily download, install and manipulate gems on your system.
59.What is Session and Cookies?
A.Session is used to store user information on the server side where as Cookies are used to store the information in the client side.
60.What is the basic difference between GET and POST method?
A.GET is basically for just getting (retrieving) the data, whereas POST may used to do multiple things, like storing or updating data, or ordering a product, or sending E-mail etc.
61.What id the difference between Static and Dynamic Scaffolding?
A.The Syntax of Static Scaffold is like this: ruby script/generate scaffold Home New Where New is the model and Home is your controller, In this way static scaffold takes two parameter i.e your controller name and model name, whereas in dynamic scaffolding you have to define controller and model one by one.
62.What is ORM Rails ?
A.ORM stands 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.
63.Does Ruby supports Multiple Inheritance?
A.No, Ruby supports only single Inheritance.
64.What is the difference between puts and print ?
A."puts" appends a new line and outputs each argument to a new line but print doesnt append anything and seems to separate arguments by a space.
65.What are the servers supported by ruby on rails?
A.Ruby Supports a number of Rails servers (Mongrel, WEBRICK, PHUSION, Passenger, etc..depending on the specific platforms). For each Rails application project, RubyMine provides default Rails run/debug configurations for the production and development environments.
66. Can we use two databases into a single application?
A.Yes, Definitely. magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time.
67.What is scope?
A. Scopes are nothing more than SQL scope fragments. By using these fragments one can cut down on having to write long queries each time you access content.
68.What deployment tool do you use?
A.Capistrano is a popular deployment tool, it allows developers to push code from their desktop to the servers. you can also use chef as a deployment tool for your project.
69.What is request.xhr?
A.A request.xhr tells the controller that the new Ajax request has come, It always return TRUE or FALSE.
70.How to serialize data with YAML?
A.YAML is a straight forward machine parsable data serialization format, designed for human readability and interaction with scripting language such as Perl and Python. YAML is optimized for data serialization, formatted dumping, configuration files, log files, internet messaging and filtering.
71.What is Active Record?
A.Active Record are like Object Relational Mapping(ORM), where classes are mapped to table and objects are mapped to colums in the table.
72.What is Mixin ?
A.Ruby does not suppoprt mutiple inheritance directly but Ruby Modules have another, wonderful use. At a stroke, they pretty much eliminate the need for multiple inheritance, providing a facility called a mixin. Mixins give you a wonderfully controlled way of adding functionality to classes.
73.What is purpose of RJs in Rails ?
A.RJS is a template (similar to an html.erb file) that generates JavaScript which is executed in an eval block by the browser in response to an AJAX request. It is sometimes used (incorrectly?) to describe the JavaScript, Prototype, and Scriptaculous Helpers provided by Rails. This may Help you more.
74.What is an observer?
A.Observer serves as a connection point between models and some other subsystem whose functionality is used by some of other classes, such as email notification. It is loose coupling in contract with model callback.
75.What is a sweeper in rails?
A.Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change. They do this by being half-observers, half-filters and implementing callbacks for both roles. You can get more Informations here.
76.How can you list all routes for an application?
A.By writing rake routes in the terminal we can list out all routes in an application.
77. Is it possible to embed partial views inside layouts? How?
A.Yes it is possible. 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.
78.What is rake?
A.rake is command line utility of rails. Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility make, and uses a Rakefile and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.
79.What is Rails?
A.Rails is a extremely productive web-application framework written in Ruby language by David Hansson.Rails are an open source Ruby framework for developing database-backend web applications.Rails include everything needed to create a database-driven web application using the Model-View-Controller (MVC) pattern.
80.Explain about RESTful Architecture.
A.RESTful: REST stands for Representational State Transfer. REST is an architecture for designing both web applications and application programming interfaces (API's), that's uses HTTP. RESTful interface means clean URLs, less code, CRUD interface. CRUD means Create-READ-UPDATE-DESTROY. In REST, they add 2 new verbs, i.e, PUT, DELETE.
81.What is meant by action pack?
A.Action Pack: Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch. The VC part of MVC.
82.What is meant by action support?
A.Active Support: Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.
83.What do you mean by render?
A.render causes rails to generate a response whose content is provided by rendering one of your templates. Means, it will direct goes to view page.
84.What do you mean by redirect_to?
A.redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.
85.What are helpers and how to use helpers in ROR?
A.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.
86.What is meant by Action Controller?
A.Action Controller: Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action.
87.Explain about the programming language ruby?
A.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.
88.What is meant by Action View?
A.Action View: Action View manages the views of your Rails application. It can create both HTML and XML output by default.
89.What is meant by Action Dispatch?
A.Action Dispatch: Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application. Rack applications are a more advanced topic and are covered in a separate guide called Rails on Rack.
90.What is meant by action mailer?
A.Action Mailer: Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.
91.What is meant by Active Model?
A.Active Model: Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.
92.What is meant by Active Record?
A.Active Record: 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.
93.What is meant by Active Resource?
A.Active Resource: Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.
94.How to use two databases into a single application?
A.magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time. sudo gem install magic_multi_connection. After installing this gem, just add this line at bottom of your environment.rb require 'magic_multi_connection'
95.What are the various changes between the Rails Version 2 and 3?
A. Introduction of bundler (new way to manage your gem dependencies), Gemfile and Gemfile.lock (where all your gem dependencies lies, instead of environment.rb) and HTML5 support.
96.What is TDD and BDD?
A.TDD stands for Test-Driven-Development and BDD stands for Behavior-Driven-Development.
97.What do you mean by Naming Convention in Rails?
A.Variables,Class and Module,Database Table,Model and Controller are naming convention in rails.
98.What is the log that has to seen to check for an error in ruby rails?
A.Rails will report errors from Apache in log/apache.log and errors from the ruby code in log/development.log. If you having a problem, do have a look at what these log are saying.
99.How you run your Rails application without creating databases?
A.You can run your application by uncommenting the line in environment.rb path=> rootpath conf/environment.rb config.frameworks- = [action_web_service, :action_mailer, :active_record
100.How you run your Rails application without creating databases?
A.You can run your application by uncommenting the line in environment.rb path=> rootpath conf/environment.rb config.frameworks- = [action_web_service, :action_mailer, :active_record
1. Rails is a extremely productive web-application framework written in Ruby language by David Hansson.
2. Rails are an open source Ruby framework for developing database-backend web applications.
3. Rails include everything needed to create a database-driven web application using the Model-View-Controller (MVC) pattern.
2. What Are The Various Components Of Rail?
1. Action Pack: Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch. The “VC” part of “MVC”.
Action Controller: Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action.
Services provided by Action Controller include session management, template rendering, and redirect management.
Action View: Action View manages the views of your Rails application. It can create both HTML and XML output by default.
Action View manages rendering templates, including nested and partial templates, and includes built-in AJAX support.
Action Dispatch: Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application. Rack applications are a more advanced topic and are covered in a separate guide called Rails on Rack.
2. Action Mailer: Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.
3. Active Model: Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.
4. Active Record: 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.
5. Active Resource: Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.
6. Active Support: Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.
3. Explain About Restful Architecture?
RESTful: REST stands for Representational State Transfer. REST is an architecture for designing both web applications and application programming interfaces (API’s), that’s uses HTTP.
RESTful interface means clean URLs, less code, CRUD interface. CRUD means Create-READ-UPDATE-DESTROY. In REST, they add 2 new verbs, i.e, PUT, DELETE.
4. Why Ruby On Rails?
There are lot of advantages of using ruby on rails.
1. DRY Principal( Don’t Repeat Yourself): It is a principle of software development aimed at reducing repetition of code. “Every piece of code must have a single, unambiguous representation within a system”
2. Convention over Configuration: Most web development framework for .NET or Java force you to write pages of configuration code. If you follow suggested naming conventions, Rails doesn’t need much configuration.
3. Gems and Plugins: RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing ruby programs and library.
Plugins: A Rails plugin is either an extension or a modification of the core framework. It provides a way for developers to share bleeding-edge ideas without hurting the stable code base. We need to decide if our plugin will be potentially shared across different Rails applications.
4. Scaffolding: Scaffolding is a meta-programming method of building database-backend software application. It is a technique supported by MVC frameworks, in which programmer may write a specification, that describes how the application database may be used. There are two type of scaffolding:
-static: Static scaffolding takes 2 parameter i.e your controller name and model name.
-dynamic: In dynamic scaffolding you have to define controller and model one by one.
5. Rack Support: Rake is a software task management tool. It allows you to specify tasks and describe dependencies as well as to group tasks in a namespace.
6. Metaprogramming: Metaprogramming techniques use programs to write programs.
7. Bundler: Bundler is a new concept introduced in Rails 3, which helps you to manage your gems for application. After specifying gem file, you need to do a bundle install.
8. Rest Support.
9. Action Mailer
5. What Do You Mean By Render And Redirect_to?
render causes rails to generate a response whose content is provided by rendering one of your templates. Means, it will direct goes to view page.
redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.
6. What Is Orm In Rails?
ORM tends for Object-Relationship-Model, where Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.
7. How Many Types Of Associations Relationships Does A Model Have?
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.
8. What Are Helpers And How To Use Helpers In Ror?
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.
9. What Are Filters?
Filters are methods that run “before”, “after” or “around” a controller action. Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application.
10. What Is Mvc? And How It Works?
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.
11. What Is Session And Cookies?
Session is used to store user information on the server side. Maximum size is 4 kb. Cookies are used to store information on the browser side or we can say client side.
12. What Is Request.xhr?
A request.xhr tells the controller that the new Ajax request has come, It always return Boolean values (TRUE or FALSE)
13. What Things We Can Define In The Model?
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
14. How Many Types Of Callbacks Available In Ror?
1. before_validation
2. before_validation_on_create
3. validate_on_create
4. after_validation
5. after_validation_on_create
6. before_save
7. before_create
8. after_create
9. after_save
15. How To Serialize Data With Yaml?
YAML is a straight forward machine parsable data serialization format, designed for human readability and interaction with scripting language such as Perl and Python.
YAML is optimized for data serialization, formatted dumping, configuration files, log files, internet messaging and filtering.
16. How To Use Two Databases Into A Single Application?
magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time.
sudo gem install magic_multi_connection. After installing this gem, just add this line at bottom of your environment.rb require “magic_multi_connection”
17. What Are The Various Changes Between The Rails Version 2 And 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. HTML5 support
18. What Is Tdd And Bdd?
TDD stands for Test-Driven-Development and BDD stands for Behavior-Driven-Development.
19. What Are The Servers Supported By Ruby On Rails?
RoR was generally preferred over WEBrick server at the time of writing, but it can also be run by:
Lighttpd (pronounced ‘lighty’) is an open-source web server more optimized for speed-critical environments.
Abyss Web Server- is a compact web server available for windows, Mac osX and Linux operating system. Apache and nginx
20. What Do You Mean By Naming Convention In Rails.
Variables: Variables are named where all letters are lowercase and words are separated by underscores. E.g: total, order_amount.
Class and Module: Classes and modules uses MixedCase and have no underscores, each word starts with a uppercase letter. Eg: InvoiceItem
Database Table: Table name have all lowercase letters and underscores between words, also all table names to be plural. Eg: invoice_items, orders etc
Model: The model is named using the class naming convention of unbroken MixedCase and always the singular of the table name.
For eg: table name is might be orders, the model name would be Order. Rails will then look for the class definition in a file called order.rb in /app/model directory. If the model class name has multiple capitalized words, the table name is assumed to have underscores between these words.
Controller: controller class names are pluralized, such that Orders Controller would be the controller class for the orders table. Rails will then look for the class definition in a file called orders_controlles.rb in the /app/controller directory.
21. What Is The Log That Has To Seen To Check For An Error In Ruby Rails?
Rails will report errors from Apache in log/apache.log and errors from the ruby code in log/development.log. If you having a problem, do have a look at what these log are saying.
22. How You Run Your Rails Application Without Creating Databases?
You can run your application by uncommenting the line in environment.rb
path=> rootpath conf/environment.rb
config.frameworks-=[action_web_service,:action_mailer,:active_record
23. How To Use Sql Db Or Mysql Db Without Defining It In The Database.yml?
You can use ActiveRecord anywhere
require “rubygems”
require “active_record”
ActiveRecord::Base.establish_connection({ :adapter=> ‘postgresql’, :user=>’foo’, :password=> ‘abc’, :database => ’whatever’})
24. Get And Post Method?
GET is basically for just getting (retrieving) data, whereas POST may involve anything, like storing or updating data, or ordering a product, or sending E-mail.
25. What Is The Difference Between Static And Dynamic Scaffolding?
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.
26. How Many Types Of Relationships Does A Model Has?
1. has_one
2. belongs_to
3. has_many
4. has_many :through
27. Difference Between Render And Redirect?
render example: render :action, render :partial etc. redirect example: redirect_to :controller => ‘users’, :action => ‘new’
28. What Is Active Record?
Active Record are like Object Relational Mapping(ORM), where classes are mapped to table and objects are mapped to columns in the table.
29. Ruby Supports Single Inheritance/multiple Inheritance Or Both?
Ruby Supports only Single Inheritance
30. What Is Bundler?
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.
31. What Is The Newest Approach For Find(:all) In Rails 3?
Model.where(:activated => true)
32. What Is The Role Of Mvc Architecture In Ruby On Rails?
MVC (Model-View-Controller) is the architecture that provides flexibility and scalability of the applications.
It is almost having the same concept in any other language like PHP, Perl or Python. It is one of the major used architecture involved today due to its simplicity.
Controller is the main part in this kind of architecture where it handles the request that is coming from another controller.
Controller contacts the view and passes on the request to the view and it also interacts with the model to define the type of request.
Model is responsible for interacting with the database and provides the responses to the controller.
Controller takes the response and gives the response in the output form to the user that has made the request.
33. What Are The Components Defined In The Model From Mvc Architecture?
The components involved in defining the model are as follows:
Validations: this is one of the very essential components and it defines the validations that are being put up on the input type of stream like validate_presence_of, format_of, etc.
Relationship: this is another type of component that describe the relationship between different types of components and it shows the relationship in the form of has_one, has_many, etc.
Callbacks: this is essential when it comes to respond after the failure and it allows the application to have certain functionality during failure. This can be given as before_save, after_save, etc.
Validation group settings: allow users to define the installed plugin settings.
Active record association relationship: allows current records to be actively having the relationship between one another.
34. Choosing Between Belongs_to And Has_one?
If you want to set up a one-to-one relationship between two models, you'll need to add belongs_to to one, and has_one to the other. How do you know which is which?
The distinction is in where you place the foreign key (it goes on the table for the class declaring the belongs_to association), but you should give some thought to the actual meaning of the data as well. The has_one relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier.
35. Render Vs. Redirect_to In Ruby On Rails ?
render will render a particular view using the instance variables available in the action.
For example if a render was used for the new action, when a user goes to /new, the new action in the controller is called, instance variables are created and then passed to the new view. Rails creates the html for that view and returns it back to the user's browser. This is what you would consider a normal page load.
redirect_to will send a redirect to the user’s browser telling it to re-request a new URL as 302 redirect response. Then the browser will send a new request to that URL and it will go through the action for that URL, oblivious to the fact that it was redirected to. None of the variables created in the action that caused the redirect will be available to the redirected view. This is what happens when you click on ‘Create’ in a form and the object is created and you’re redirected to the edit view for that object.
36. What Is The Difference Between Save And Save?
Save! performs all validations and callbacks. If any validation returns false, save! throws an error and canceles the save.
Save does not throw any error in the case above, but canceles the save. Also, the validators can be bypassed.
37. What Is The Difference Between Delete And Destroy ?
The delete method essentially deletes a row (or an array of rows) from the database. Destroy on the other hand allows for a few more options. First, it will check any callbacks such as before_delete, or any dependencies that we specify in our model. Next, it will keep the object that just got deleted in memory; this allows us to leave a message saying something like “ 'Object_name' has been deleted.” Lastly, and most importantly, it will also delete any child objects associated with that object!
38. What Are Filters? And How Many Types Of Filters Are There In Ruby ?
Filters are methods that are run before, after or "around" a controller action.
Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application.
Filter can take one of three forms: method reference (symbol), external class, or inline method (proc).
after_filter
append_after_filter
append_around_filter
append_before_filter
around_filter
before_filter
filter_chain
prepend_after_filter
prepend_around_filter
prepend_before_filter
skip_after_filter
skip_before_filter
skip_filter
39. What Is The Flash?
The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash.
flash is a object of Actiondispatch class.
40. Difference Between Argument And Parameter In Ruby On Rails ?
A parameter represents a value that the method expects you to pass when you call it.
An argument represents the value you pass to a method parameter when you call the method. The calling code supplies the arguments when it calls the method.
In simple words, parameters appear in method definitions; arguments appear in method calls.
For example, in below method, variables param1 and param2 are the parameters
def foo_method(param1, param2):
.......
end
while calling the method, arg1 and arg2 are the arguments
foo_method(arg1, arg2)
41. What Is The Difference Between Symbol And String ?
The symbol in Ruby on rails act the same way as the string but the difference is in their behaviors that are opposite to each other.
The difference remains in the object_id, memory and process time for both of them when used together at one time.
Strings are considered as mutable objects. Whereas, symbols, belongs to the category ofimmutable.
Strings objects are mutable so that it takes only the assignments to change the object information. Whereas, information of, immutable objects gets overwritten.
-String objects are written like
o "string object jack".object_id #=>2250 or
o "string object jack".to_sym.object_id #=> 2260, and
o "string object jack". to_s_object_id #=> 2270
Symbols are used to show the values for the actions like equality or non-equality to test the symbols faster then the string values.
42. Write A Program To Show The Functionality Of Request.xhr In Ruby On Rails ?
Request from the request.xhr displays the controller that manages and creates the new AJAX that is being handled by the new controller.
The Boolean values that are retured should generate only TRUE or FALSE. These values are used to be inserted for this purpose.
The request.xhr is being shown in a program shown below as:
def create
return unless request.xhr?
@imageable = find_imageable
@image = @imageable.images.build(params[:imageable])
@image.save
render :layout => false
end
43. What Are The Different Components Of Rails ?
The components used in Rails are as follows:
Action Controller: it is the component that manages all other controllers and process the incoming request to the Rails application.
It extracts the parameters and dispatches the response when an action is performed on the application.
It provides services like session management, template rendering and redirect management.
Action View: it manages the views of the Rails application and it creates the output in both HTML and XML format.
It also provides the management of the templates and gives the AJAX support that is being used with the application.
Active Record: It provides the base platform for the models and gets used in the Rails application. It provides the database independence, CRUID functionality, search capability and setting the relationship between different models.
Action Mailer: It is a framework that provides email services to build the platform on which flexible templates can be implemented.
44. What Is The Purpose Of Load, Auto_load, And Require_relative In Ruby ?
Load allows the process or a method to be loaded in the memory and it actually processes the execution of the program used in a separate file.
It includes the classes, modules, methods and other files that executes in the current scope that is being defined. It performs the inclusion operation and reprocesses the whole code every time the load is being called.
require is same as load but it loads code only once on first time.
Auto_load: this initiates the method that is in hat file and allows the interpreter to call the method.
require_relative: allows the loading to take place of the local folders and files.
45. What Is A Proc ?
Everyone usually confuses procs with blocks, but the strongest rubyist can grok the true meaning of the question.
Essentially, Procs are anonymous methods (or nameless functions) containing code. They can be placed inside a variable and passed around like any other object or scalar value. They are created by Proc.new, lambda, and blocks (invoked by the yield keyword).
Blocks are very handy and syntactically simple, however we may want to have many different blocks at our disposal and use them multiple times. As such, passing the same block again and again would require us to repeat ourself. However, as Ruby is fully object-oriented, this can be handled quite cleanly by saving reusable code as an object itself. This reusable code is called aProc (short for procedure). The only difference between blocks and Procs is that a block is a Proc that cannot be saved, and as such, is a one time use solution.
46. What Is Unit Testing (in Classical Terms)? What Is The Primary Technique When Writing A Test ?
Unit testing, simply put, is testing methods -- the smallest unit in object-oriented programming. Strong candidates will argue that it allows a developer to flesh out their API before it's consumed by other systems in the application.
The primary way to achieve this is to assert that the actual result of the method matches an expected result.
47. What Is The Difference Between Nil And False In Ruby ?
False is a boolean datatype, Nil is not a data type it have object_id 4.
• What Are The Looping Structures Available In Ruby ?
• for..in
• untill..end
• while..end
do..end
Note: You can also use each to iterate a array as loop not exactly like loop
48. How Is Visibility Of Methods Changed In Ruby (encapsulation) ?
By applying the access modifier : Public , Private and Protected access Modifier
49. Dynamic Finders ?
For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called first_name on your Client model for example, you getfind_by_first_name and find_all_by_first_name for free from Active Record. If you have a locked field on the Client model, you also get find_by_locked and find_all_by_lockedmethods.
You can also use find_last_by_* methods which will find the last record matching your argument.
You can specify an exclamation point (!) on the end of the dynamic finders to get them to raise an ActiveRecord::RecordNotFound error if they do not return any records, like Client.find_by_name!("Ryan")
If you want to find both by name and locked, you can chain these finders together by simply typing "and" between the fields. For example, Client.find_by_first_name_and_locked("Ryan", true).
50. Finding By Sql ?
If you'd like to use your own SQL to find records in a table you can use find_by_sql. The find_by_sql method will return an array of objects even if the underlying query returns just a single record.
For example you could run this query:
Client.find_by_sql("SELECT * FROM clients
INNER JOIN orders ON clients.id = orders.client_id ORDER clients.created_at desc")
find_by_sql provides you with a simple way of making custom calls to the database and retrieving instantiated objects.
51.Is Rails scalable?
A.Yes Rails gives you complete freedom to use all traditional means of scaling an application. Things like memcached, caching full pages, caching fragments are all supported.
52.How can you safeguard a rails application from SQL injection attack?
A.Rails already has the logic built into it to prevent SQL injection attacks if you follow the right syntax.
53.How can you secure a rails application?
A.Rails has a lot of in-built capabilities to deal with common web-security issues. Like : SQL Injection, Cross-Site , Session fixation and Session hijacking, Captcha
54.Can you tell me a few good community resources for Rails?
A.Stackoverflow, Github, various Meetup groups.
55.Where would you reach out to get the community to answer your questions?
A.Stackoverflow and meetup groups.
56.In which Programming language was Ruby written?
A.Ruby was written in C language and Ruby on Rails written in Ruby
57.How many types of relationships does a Model has?
A.has_one, belongs_to, has_many and has_many :through
58.What is Ruby Gems?
A.Ruby Gem is a software package, commonly called a "gem". Gem contains a packaged Ruby application or library. The Ruby Gems software itself allows you to easily download, install and manipulate gems on your system.
59.What is Session and Cookies?
A.Session is used to store user information on the server side where as Cookies are used to store the information in the client side.
60.What is the basic difference between GET and POST method?
A.GET is basically for just getting (retrieving) the data, whereas POST may used to do multiple things, like storing or updating data, or ordering a product, or sending E-mail etc.
61.What id the difference between Static and Dynamic Scaffolding?
A.The Syntax of Static Scaffold is like this: ruby script/generate scaffold Home New Where New is the model and Home is your controller, In this way static scaffold takes two parameter i.e your controller name and model name, whereas in dynamic scaffolding you have to define controller and model one by one.
62.What is ORM Rails ?
A.ORM stands 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.
63.Does Ruby supports Multiple Inheritance?
A.No, Ruby supports only single Inheritance.
64.What is the difference between puts and print ?
A."puts" appends a new line and outputs each argument to a new line but print doesnt append anything and seems to separate arguments by a space.
65.What are the servers supported by ruby on rails?
A.Ruby Supports a number of Rails servers (Mongrel, WEBRICK, PHUSION, Passenger, etc..depending on the specific platforms). For each Rails application project, RubyMine provides default Rails run/debug configurations for the production and development environments.
66. Can we use two databases into a single application?
A.Yes, Definitely. magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time.
67.What is scope?
A. Scopes are nothing more than SQL scope fragments. By using these fragments one can cut down on having to write long queries each time you access content.
68.What deployment tool do you use?
A.Capistrano is a popular deployment tool, it allows developers to push code from their desktop to the servers. you can also use chef as a deployment tool for your project.
69.What is request.xhr?
A.A request.xhr tells the controller that the new Ajax request has come, It always return TRUE or FALSE.
70.How to serialize data with YAML?
A.YAML is a straight forward machine parsable data serialization format, designed for human readability and interaction with scripting language such as Perl and Python. YAML is optimized for data serialization, formatted dumping, configuration files, log files, internet messaging and filtering.
71.What is Active Record?
A.Active Record are like Object Relational Mapping(ORM), where classes are mapped to table and objects are mapped to colums in the table.
72.What is Mixin ?
A.Ruby does not suppoprt mutiple inheritance directly but Ruby Modules have another, wonderful use. At a stroke, they pretty much eliminate the need for multiple inheritance, providing a facility called a mixin. Mixins give you a wonderfully controlled way of adding functionality to classes.
73.What is purpose of RJs in Rails ?
A.RJS is a template (similar to an html.erb file) that generates JavaScript which is executed in an eval block by the browser in response to an AJAX request. It is sometimes used (incorrectly?) to describe the JavaScript, Prototype, and Scriptaculous Helpers provided by Rails. This may Help you more.
74.What is an observer?
A.Observer serves as a connection point between models and some other subsystem whose functionality is used by some of other classes, such as email notification. It is loose coupling in contract with model callback.
75.What is a sweeper in rails?
A.Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change. They do this by being half-observers, half-filters and implementing callbacks for both roles. You can get more Informations here.
76.How can you list all routes for an application?
A.By writing rake routes in the terminal we can list out all routes in an application.
77. Is it possible to embed partial views inside layouts? How?
A.Yes it is possible. 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.
78.What is rake?
A.rake is command line utility of rails. Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility make, and uses a Rakefile and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.
79.What is Rails?
A.Rails is a extremely productive web-application framework written in Ruby language by David Hansson.Rails are an open source Ruby framework for developing database-backend web applications.Rails include everything needed to create a database-driven web application using the Model-View-Controller (MVC) pattern.
80.Explain about RESTful Architecture.
A.RESTful: REST stands for Representational State Transfer. REST is an architecture for designing both web applications and application programming interfaces (API's), that's uses HTTP. RESTful interface means clean URLs, less code, CRUD interface. CRUD means Create-READ-UPDATE-DESTROY. In REST, they add 2 new verbs, i.e, PUT, DELETE.
81.What is meant by action pack?
A.Action Pack: Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch. The VC part of MVC.
82.What is meant by action support?
A.Active Support: Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.
83.What do you mean by render?
A.render causes rails to generate a response whose content is provided by rendering one of your templates. Means, it will direct goes to view page.
84.What do you mean by redirect_to?
A.redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.
85.What are helpers and how to use helpers in ROR?
A.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.
86.What is meant by Action Controller?
A.Action Controller: Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action.
87.Explain about the programming language ruby?
A.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.
88.What is meant by Action View?
A.Action View: Action View manages the views of your Rails application. It can create both HTML and XML output by default.
89.What is meant by Action Dispatch?
A.Action Dispatch: Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application. Rack applications are a more advanced topic and are covered in a separate guide called Rails on Rack.
90.What is meant by action mailer?
A.Action Mailer: Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.
91.What is meant by Active Model?
A.Active Model: Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.
92.What is meant by Active Record?
A.Active Record: 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.
93.What is meant by Active Resource?
A.Active Resource: Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.
94.How to use two databases into a single application?
A.magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time. sudo gem install magic_multi_connection. After installing this gem, just add this line at bottom of your environment.rb require 'magic_multi_connection'
95.What are the various changes between the Rails Version 2 and 3?
A. Introduction of bundler (new way to manage your gem dependencies), Gemfile and Gemfile.lock (where all your gem dependencies lies, instead of environment.rb) and HTML5 support.
96.What is TDD and BDD?
A.TDD stands for Test-Driven-Development and BDD stands for Behavior-Driven-Development.
97.What do you mean by Naming Convention in Rails?
A.Variables,Class and Module,Database Table,Model and Controller are naming convention in rails.
98.What is the log that has to seen to check for an error in ruby rails?
A.Rails will report errors from Apache in log/apache.log and errors from the ruby code in log/development.log. If you having a problem, do have a look at what these log are saying.
99.How you run your Rails application without creating databases?
A.You can run your application by uncommenting the line in environment.rb path=> rootpath conf/environment.rb config.frameworks- = [action_web_service, :action_mailer, :active_record
100.How you run your Rails application without creating databases?
A.You can run your application by uncommenting the line in environment.rb path=> rootpath conf/environment.rb config.frameworks- = [action_web_service, :action_mailer, :active_record
No comments:
Post a Comment