Friday 6 February 2015

interview questions for ruby on rails developer (Page 2)

11. Difference between render and redirect? | Ruby On Rails Questions
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? | Ruby On Rails Questions
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 ? | Ruby On Rails Questions
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. | Ruby On Rails Questions
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? | Ruby On Rails Questions
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? | Ruby On Rails Questions
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? | Ruby On Rails Questions
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? | Ruby On Rails Questions
(-) 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? | Ruby On Rails Questions
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? | Ruby On Rails Questions
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
More Questions & Answers :-

No comments:

Post a Comment