4. Everything is an object
5.times do
puts “Hello World”
end
Hello World
Hello World
Hello World
Hello World
Hello World
5.class
=> Fixnum=> Fixnum
nil.class
=> NilClass
5. Ruby Blocks
patients.each do |patient|
if patient.ill?
physician.examine patient
else
patient.jump_for_joy!
end
end
You can group a set of instructions together
6. Open Classes
class String
def write_size
self.size
end
end
size_writer = "Tell me my size!"
puts size_writer.write_size
In Ruby, classes are never closed,
you can always add methods to an existing class.
7. Method Missing
class Dummy
def method_missing(m, *args, &block)
puts "There's no method #{m}"
end
end
Dummy.new.anything
method_missing is in part a safety net: It gives you a way to
intercept unanswerable messages and handle them gracefully
17. Active Record
-Represent models and their data
-Represent associations between these models
-Represent inheritance hierarchies through related models
-Validate models before they get persisted to the database
-Perform database operations in an object-oriented fashion.
32. Active Record Callbacks
-Active Record provides hooks into this object life cycle so
that you can control your application and its data.
-Callbacks allow you to trigger logic before or after an
alteration of an object's state.
34. When does it get triggered?
-Creating an Object
before_validation
after_validation
before_save
around_save
before_create
around_create
after_create
after_save
-Updating an Object
before_validation
after_validation
before_save
around_save
before_update
around_update
after_update
after_save
-Destroying an Object
before_destroy
around_destroy
after_destroy
35. Active Record Associations
They make common operations simpler and easier in your code.
-Get a user's all posts
-Get the author of a post
48. Action View
-Action View is responsible for compiling the response.
-Action View templates are written using embedded Ruby in tags mingled with HTML.
-All view files must be in app/views folder
53. Controller Layer
-Controller is responsible for making sense of the request and producing the
appropriate output
-Rails favors pluralization of the last word in the controller's name
ClientsController
SiteAdminsController
PostsController
54.
55. Routing
-The Rails router recognizes URLs and dispatches them to a controller's action.
-Generate paths and URLs, avoiding the need to hardcode strings in your views.
routes.rb
Request
index.html.erb