ruby and rails - advanced training (cybage)
DESCRIPTION
Cybage Advanced Training - customisedTRANSCRIPT
![Page 1: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/1.jpg)
Ruby and Rails Advanced Training
@gautamrege @joshsoftware
![Page 2: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/2.jpg)
Agenda - Day 1Discuss Ruby basics
Syntax, classes, modules. Meta-programming. Closures
Rails concepts Discussion around Rails design patterns. ActiveSupport Concern Rails engines
![Page 3: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/3.jpg)
Agenda - Day 2Discuss your current Applications.
Gems currently in use
Resolving problems.
ActiveResource
Rails Security
Data Caching
Performace monitoring and improvement
![Page 4: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/4.jpg)
Ruby is easy, right?
![Page 5: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/5.jpg)
Ruby is easy, right?
1 + 1
![Page 6: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/6.jpg)
Ruby is easy, right?
1 + 1
1.+(1)
![Page 7: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/7.jpg)
Ruby is easy, right?
1 + 1
1.+(1)
1.+ 1
![Page 8: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/8.jpg)
Ruby is easy, right?
1 + 1
1.+(1)
1.+ 1
1.send(:+, 1)
![Page 9: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/9.jpg)
How many objects?
![Page 10: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/10.jpg)
How many objects?
1 + 2 + 3
![Page 11: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/11.jpg)
How many objects?
1 + 2 + 3
![Page 12: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/12.jpg)
How many objects?
1 + 2 + 3
( 1.+(2) ).+(3)
![Page 13: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/13.jpg)
How many objects?
1 + 2 + 3
( 1.+(2) ).+(3)
![Page 14: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/14.jpg)
How many objects?
1 + 2 + 3
( 1.+(2) ).+(3)
![Page 15: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/15.jpg)
How many objects?
1 + 2 + 3
( 1.+(2) ).+(3)
![Page 16: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/16.jpg)
How many objects?
1 + 2 + 3
( 1.+(2) ).+(3)
![Page 17: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/17.jpg)
How many objects?
1 + 2 + 3
( 1.+(2) ).+(3)
![Page 18: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/18.jpg)
How many objects?
1 + 2 + 3
( 1.+(2) ).+(3) FIVE objects
![Page 19: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/19.jpg)
Everything in Ruby
is an object
on which we call a method
to which we pass parameters
and an optional block of code
![Page 20: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/20.jpg)
So, you know Ruby?
![Page 21: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/21.jpg)
So, you know Ruby?
a[1] # What is the data type of a?
![Page 22: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/22.jpg)
So, you know Ruby?
a[1] # What is the data type of a?
a = [‘a’, ‘b’] # Array
![Page 23: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/23.jpg)
So, you know Ruby?
a[1] # What is the data type of a?
a = [‘a’, ‘b’] # Array
a = { 1 => ‘a’} # Hash
![Page 24: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/24.jpg)
So, you know Ruby?
a[1] # What is the data type of a?
a = [‘a’, ‘b’] # Array
a = { 1 => ‘a’} # Hash
a = “abc” # String
![Page 25: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/25.jpg)
So, you know Ruby?
a[1] # What is the data type of a?
a = [‘a’, ‘b’] # Array
a = { 1 => ‘a’} # Hash
a = “abc” # String
a = Proc.new { | x | p x } # proc
![Page 26: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/26.jpg)
Multiplication
![Page 27: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/27.jpg)
Multiplication
[1, 2, 3] * 2
![Page 28: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/28.jpg)
Multiplication
[1, 2, 3] * 2
# => [1, 2, 3, 1, 2, 3]
![Page 29: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/29.jpg)
Multiplication
[1, 2, 3] * 2
# => [1, 2, 3, 1, 2, 3]
[1, 2, 3] * “%”
![Page 30: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/30.jpg)
Multiplication
[1, 2, 3] * 2
# => [1, 2, 3, 1, 2, 3]
[1, 2, 3] * “%”
# => “1%2%3”
![Page 31: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/31.jpg)
There’s always an easier way
Summation of [1, 2, 3, 4]
![Page 32: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/32.jpg)
Non-ruby way!sum = 0 !
for i in [1, 2, 3, 4] sum += i end !
p sum
![Page 33: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/33.jpg)
The Amateur!
sum = 0 !
[1, 2, 3, 4].each do |i| sum += i end !
p sum
![Page 34: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/34.jpg)
The Professional!
!
[1, 2, 3, 4].inject(0) do |sum, i| sum + i end
![Page 35: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/35.jpg)
The Expert!
!
[1, 2, 3, 4].inject(:+)
![Page 36: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/36.jpg)
Exceptions… never! class Base
def method_missing(name, *args, &blk)
puts “Unknown method #{name}called.”
end
end
b = Base.new
b.wtf
![Page 37: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/37.jpg)
What’s in a name?# User(id: integer, name: string)
class User < ActiveRecord::Base
end u = User.name
u.name
u.name = “Gautam”
![Page 38: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/38.jpg)
Accessing Dataclass User
def initialize
@name = “someone”
end
end u = User.name
u.name
u.name = “Gautam”
![Page 39: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/39.jpg)
Protected & Private
Private methods are inherited
Protected method can be called on another object in same lineage
What the …
![Page 40: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/40.jpg)
Module Mixinsclass Shaktiman
include Spiderman
include Superman
end
irb> Shaktiman.ancestors
=> [ Shaktiman, Superman, Spiderman …]
![Page 41: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/41.jpg)
Closures
sum = 0
[1, 2, 3, 4].each do |x|
sum += i
end
p sum
Anonymous functions? Local variables scope?
![Page 42: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/42.jpg)
Closures!
Context sensitive block of code
![Page 43: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/43.jpg)
Rails Design Patterns
![Page 44: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/44.jpg)
Rails Design Patterns
Singleton
![Page 45: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/45.jpg)
Rails Design Patterns
Singleton
Factory
![Page 46: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/46.jpg)
Rails Design Patterns
Singleton
Factory
Observer
![Page 47: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/47.jpg)
Rails Design Patterns
Singleton
Factory
Observer
…
![Page 48: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/48.jpg)
Rails Design Patterns
Singleton
Factory
Observer
…
You cannot learn Design Patterns!
!
You need to experience them
![Page 49: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/49.jpg)
SOLID Design Patterns
![Page 50: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/50.jpg)
SOLID principles
S - Single Responsibilty
O - Open / Closed
L - Liskov Substituion
I - Interface Segregation
D - Dependency Inversion
![Page 51: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/51.jpg)
Single Responsibility
Serves only one purpose.
Models - manage data
Controllers - manage logic
No logic in views!
![Page 52: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/52.jpg)
Open / Closed
Open for Extension
Closed for modification
![Page 53: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/53.jpg)
Open / Closed
Open for Extension
Closed for modification
ParseFeed
![Page 54: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/54.jpg)
Open / Closed
Open for Extension
Closed for modification
ParseFeed
Atom RSS
ParseFeed
![Page 55: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/55.jpg)
Liskov Substituion
Functionality should work for all derived classes.
Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is subtype of T
![Page 56: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/56.jpg)
Interface Segregation
Classification based on behaviour
Vehicle
AirRoad
TrainCar RocketAirplane
![Page 57: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/57.jpg)
Dependency Inversion
High level modules should not depend on low level modules
Modules should depend on abstractions
Details should depend on abstractions
![Page 58: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/58.jpg)
ActiveSupport Concern
![Page 59: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/59.jpg)
Without ActiveSupport Concerns
module Foo
def self.included(base)
base.class_eval do
scope :disable, -> { where(disabled: true) }
end
end
end
class Base include Foo end
![Page 60: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/60.jpg)
With ActiveSupport Concerns
module Foo
extend ActiveSupport::Concern
included do
scope :disable, -> { where(disabled: true) }
end
endclass Base include Foo end
![Page 61: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/61.jpg)
Dependent Modules
![Page 62: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/62.jpg)
Dependent Modulesmodule Foo
def self.included(base)
base.class_eval do
def self.foo_method
end
end
end
end
![Page 63: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/63.jpg)
Dependent Modulesmodule Foo
def self.included(base)
base.class_eval do
def self.foo_method
end
end
end
end
module Bar
def self.included(base)
base.foo_method
end
end
![Page 64: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/64.jpg)
Dependent Modulesmodule Foo
def self.included(base)
base.class_eval do
def self.foo_method
end
end
end
end
module Bar
def self.included(base)
base.foo_method
end
end
class Base include Foo include Bar end
![Page 65: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/65.jpg)
Dependent Modulesmodule Foo
def self.included(base)
base.class_eval do
def self.foo_method
end
end
end
end
module Bar
def self.included(base)
base.foo_method
end
end
class Base include Foo include Bar end
add module dependency #!!
![Page 66: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/66.jpg)
Module dependencies
![Page 67: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/67.jpg)
Module dependencies
module Bar
include Foo
included do
def self.foo_method
end
end
class Base include Bar end
![Page 68: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/68.jpg)
Module dependencies
module Bar
include Foo
included do
def self.foo_method
end
end
class Base include Bar end
self = Bar self != Base
![Page 69: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/69.jpg)
Module dependencies
module Bar
include Foo
included do
def self.foo_method
end
end
class Base include Bar end
self = Bar self != Base
![Page 70: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/70.jpg)
Module dependencies
module Bar
extend ActiveSupport::Concern
include Foo
included do
def self.foo_method
end
endclass Base include Bar end
no including extra modues
self = Base
![Page 71: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/71.jpg)
Rails Engines
![Page 72: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/72.jpg)
Engine power
Velocity App
CarRocket
Some custom Functionality
![Page 73: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/73.jpg)
CarRocket
Some custom functionality
![Page 74: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/74.jpg)
CarRocket
Some custom functionality
Astronaut
Shuttles
M
M
![Page 75: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/75.jpg)
CarRocket
Some custom functionality
Astronaut
Shuttles
M
M
Driver
Rto
M
1
![Page 76: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/76.jpg)
CarRocket
Some custom functionality
Astronaut
Shuttles
M
M
Driver
Rto
M
1
Company
![Page 77: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/77.jpg)
Quick Reference
rails plugin new <name> —mountable
rails g scaffold <model> <name>:<type>
test/dummy: testing engine.
![Page 78: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/78.jpg)
GamePlay - CarCreate Car engine
Create RTO scaffold
name:string code:string
Create Driver scaffold
name:string rto_id:integer has_licence:boolean
![Page 79: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/79.jpg)
Testing - Car
rake db:migrate
cd test/dummy
rails s
http://localhost:300/car
![Page 80: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/80.jpg)
GamePlay-RocketCreate Rocket engine
Create Astronaut scaffold
name:string degree:text
Create Shuttle scaffold
name:string launch_from:text
Create Space_flights scaffold
shuttle_id:integer astronaut_id:integer launch_on:date
![Page 81: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/81.jpg)
Testing - Rocket
rake db:migrate
cd test/dummy
rails s
http://localhost:3000/rocket
![Page 82: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/82.jpg)
Application Stuffrails new velocity
update Gemfile
gem ‘car’, path: <path>
gem ‘rocket’, path: <path>
config/routes:
mount Car::Engine, at: ‘/car’
mount Rocket::Engine, at: ‘/engine’
![Page 83: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/83.jpg)
Application Logic
Company scaffold
name:string make_cars:boolean make_rockets:boolean owner:string
![Page 84: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/84.jpg)
Using Application models in engines.Add migration for owner_id
class Shuttle
belongs_to :owner, class: “Company”
end
NEVER hardcode associations directly in engines. Use class option.
![Page 85: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/85.jpg)
More ???
![Page 86: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/86.jpg)
Devise Authentication
Gemfile
gem ‘devise’
rails g devise:install
rails g device user
rake db:migrate
![Page 87: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/87.jpg)
Inherit from App# rocket/app/controller/rocket/application_controller.rb
class Rocket::ApplicationController < ApplicationController
end
# shuttles_controller.rb
class ShuttleController < ApplicationControler
before_action :authenticate_user!
end
![Page 88: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/88.jpg)
ChecklistAutomatic namespace resolution.
Views that access models require to be fully resolved.
rake <engine>:install:migrations
rake railties:install:migrations
Controllers permit parameters
No hardcoded associations from top-level app.
![Page 89: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/89.jpg)
Discussions!
ActiveResource
Rails Security
Caching
Performance
Q & A
![Page 90: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/90.jpg)
ActiveResource
![Page 91: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/91.jpg)
Rails Security Authenticity Token
Protect from forgery
CSRF
SQL injection
XSS - html_safe & raw
http://guides.rubyonrails.org/security.html
![Page 92: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/92.jpg)
Rails CachingCache Store:
memory, file, memcached, ehcache, custom
Page & Action caching (DEPRECATED)
http://signalvnoise.com/posts/3113-how-key-based-cache-expiration-works
Fragment caching
Query caching
http://guides.rubyonrails.org/caching_with_rails.html
![Page 93: Ruby and rails - Advanced Training (Cybage)](https://reader031.vdocuments.us/reader031/viewer/2022020920/53fdae188d7f72a81c8b4a47/html5/thumbnails/93.jpg)
Rails PerformanceNewRelic Monitoring
Log file and debugging
Load Testing
Concurrency testing
Performance Benchmark using benchmark-ips
http://guides.rubyonrails.org/v3.2.13/performance_testing.html