SlideShare a Scribd company logo
Ruby on Rails
8/01/2015 Jānis Caune
First things first
Ruby is a programming language
Ruby Gems are Ruby packages
RubyGems is a package management
framework for Ruby
Ruby on Rails is a Web framework
Ruby on Rails is also a Ruby gem
Why Ruby?
● Designed in mid-1990s by Yukihiro Matsamuto
● "I hope to see Ruby help every programmer in the world
to be productive, and to enjoy programming, and to be
happy. That is the primary purpose of Ruby language."
● Goal is Very Nice, but what’s Ruby?
What’s Ruby?
Ruby is dynamic, reflective, object-oriented general
purpose programming language.
Also, it is very user friendly(after some time).
Also, let’s see examples and welcome to check out
Wikipedia!
Some examples
Everything is an object
-199.abs # => 199
"ice is nice".length # => 11
"ruby is cool.".index("u") # => 1
"Nice Day Isn't It?".downcase.split("").uniq.sort.join # => " '?acdeinsty"
Classes are never closed
# re-open Ruby's Time class
class Time
def yesterday
self - 86400
end
end
today = Time.now # => 2013-09-03 16:09:37 +0300
yesterday = today.yesterday # => 2013-09-02 16:09:37 +0300
Some examples
Blocks and iterators
{ puts "Hello, World!" } # note the braces
# or:
do
puts "Hello, World!"
end
array.each {|item| puts item }
array.each_index {|index| puts "#{index}: #{array[index]}" }
File.readlines('file.txt').each do |line|
puts line
end
OK, what’s RoR?
● full stack framework
● makes use of
○ Model-View-Controller
○ Don’t Repeat Yourself
○ Active Record
○ RESTful routes
○ Fat Models Skinny Controllers
● first released on 2004, as extract from Basecamp
RoR components
/app/
/app/assets/
/app/controllers/
/app/helpers/
/app/mailers/
/app/models/
/app/views/
/bin/
/config/
/db/
/lib/
/log/
/public/
/public/assets/
/public/images/
/public/javascripts/
/public/stylesheets/
/public/system/
/test/
/tmp/
/vendor/
/Gemfile
RoR tools
● rails itself:
○ rails new
○ rails g (scaffold|model|controller|migration|...)
○ rails server
● rake, the Ruby make (for running tasks defined by RoR and you):
○ rake db:migrate
○ rake assets:precompile
○ rake somelib:sometask
● bundler, takes care of project specific gems, specified in Gemfile:
○ bundle install
How to get started?
● Install RVM - much recommended!
● Install Ruby using RVM
● Install RubyGems using RVM
● Install your first gem - Rails (gem install smth)
● Now you have tools to start developing - but you need
to run the app somehow..
How to get started?
Ways to run RoR apps:
● built in webserver - rails server
● Passenger module for Apache/Nginx (recommended)
● Unicorn webserver
● Puma webserver
How do I build an app?
Easy!
rails new fabulousapp # create the app, done!
cd fabulousapp
rails g scaffold article # let’s have all at once
… edit migration, define fields …
rake db:migrate # oh, right, no DB defined
rake routes # scaffold is good for you (add default, though)
At this point, you can launch your app!
Articles need comments
Easy, just:
● create new scaffold: rails g comment
● add relation:
○ comment - belongs_to :article
○ article - has_many :comments (see plural form?)
● get the comments, e.g. in controller:
class ArticlesController < ApplicationController
def show
@article = Article.find(params[:id])
@comments = @article.comments
end
...
We want to see comments!
Each controller action should have an associated view (unless configured
otherwise):
so, for ArticlesController show action we’d have:
app/views/articles/show.html.erb
Response format can also be changed:
class ArticlesController < ApplicationController
def lazy_load
@article = Article.find(params[:id])
@comments = @article.comments
respond_with :js # Will look for app/views/articles/lazy_load.js.erb
end
...
We want to see comments!
Views in Rails are layout based
(controller defines layout):
app/views/layouts/application.html.erb
Here we see how:
- stylesheets and javascripts are
included
- what variable tag looks like
- where does controller response go
to
<!DOCTYPE html>
<html>
<head>
<title>Fabulousapp</title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-
turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
Still no comments!
Views can consist of single template:
<div class="wrapper">
<div class="center_content">
<%= article.content %>
<% if @comments.any? %>
<div class="comments_placeholder">
….
Or, they can call other views as well:
….
<% if @comments.any? %>
<%= render partial: 'comment_form', locals: {article: @article} %>
This is ugly!
Rails use SCSS and CoffeeScript for styles and frontend scripts. One can
always fall back to vanilla CSS and JS. Remember application.html.erb?
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
This will look for app/assets/javascripts/application.js
You can define JS/CSS on action scope, as controller can define layout.
Images referenced in CSS is stored in app/assets/images/
What about bad guys?
● for certain actions you can set before_filter:
class ArticlesController < ApplicationController
before_filter :require_uber_user, :only => [:delete]
def require_uber_user
current_user.uber_user
end
● CSRF token support by default
● few good auth gems available
Is there a gem for …?
● Most likely, yes.
● AND, you get to rewrite them, if needed.
My changes don’t work!
Unless development environment variable is set up, Rails
app will be run in it’s compiled state and won’t care about
code or assets changes.
To avoid it:
- set the variable already, OR
- touch tmp/restart.txt
- rake assets:precompile
Doing > Listening! Good luck!
Questions?

More Related Content

What's hot

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
AMD Developer Central
 
Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction
Kanika Gera
 
Node js
Node jsNode js
Web service Introduction
Web service IntroductionWeb service Introduction
Web service Introduction
Madhukar Kumar
 
Common Gateway Interface ppt
Common Gateway Interface pptCommon Gateway Interface ppt
Common Gateway Interface ppt
OECLIB Odisha Electronics Control Library
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
jQuery
jQueryjQuery
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
Eyal Vardi
 
Web-Development-ppt (1).pptx
Web-Development-ppt (1).pptxWeb-Development-ppt (1).pptx
Web-Development-ppt (1).pptx
RaihanUddin57
 
Nodejs
NodejsNodejs
Nodejs
Prem Sanil
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
 
Lezione 8: Introduzione ai Web Service
Lezione 8: Introduzione ai Web ServiceLezione 8: Introduzione ai Web Service
Lezione 8: Introduzione ai Web Service
Andrea Della Corte
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Thymeleaf
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
Erik van Appeldoorn
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
platico_dev
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2Dave Cross
 
Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛
Wen-Tien Chang
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 

What's hot (20)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction
 
Node js
Node jsNode js
Node js
 
Web service Introduction
Web service IntroductionWeb service Introduction
Web service Introduction
 
Common Gateway Interface ppt
Common Gateway Interface pptCommon Gateway Interface ppt
Common Gateway Interface ppt
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
jQuery
jQueryjQuery
jQuery
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Web-Development-ppt (1).pptx
Web-Development-ppt (1).pptxWeb-Development-ppt (1).pptx
Web-Development-ppt (1).pptx
 
Nodejs
NodejsNodejs
Nodejs
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Lezione 8: Introduzione ai Web Service
Lezione 8: Introduzione ai Web ServiceLezione 8: Introduzione ai Web Service
Lezione 8: Introduzione ai Web Service
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 

Viewers also liked

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
Joost Hietbrink
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
Vysakh Sreenivasan
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails Presentation
ChanHan Hy
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on Rails
Jonathan Weiss
 
Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)Konstantin Gredeskoul
 

Viewers also liked (7)

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails Presentation
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on Rails
 
Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)
 

Similar to RoR (Ruby on Rails)

Introduction to rails
Introduction to railsIntroduction to rails
Introduction to rails
Go Asgard
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
Steve Keener
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Alessandro DS
 
Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
Jim Jones
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
David Mc Donagh
 
Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)
Tobias Pfeiffer
 
FGCU Camp Talk
FGCU Camp TalkFGCU Camp Talk
FGCU Camp Talk
Mark Brooks
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
Momentum Design Lab
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
Brian Sam-Bodden
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
anides
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
Thomas Asikis
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
Gourab Mitra
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorialsunniboy
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
Jean-Baptiste Feldis
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
ssusercd195b
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016
Justin Gordon
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
Robert Postill
 

Similar to RoR (Ruby on Rails) (20)

Introduction to rails
Introduction to railsIntroduction to rails
Introduction to rails
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
 
Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)
 
FGCU Camp Talk
FGCU Camp TalkFGCU Camp Talk
FGCU Camp Talk
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
 

Recently uploaded

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 

Recently uploaded (20)

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 

RoR (Ruby on Rails)

  • 1. Ruby on Rails 8/01/2015 Jānis Caune
  • 2. First things first Ruby is a programming language Ruby Gems are Ruby packages RubyGems is a package management framework for Ruby Ruby on Rails is a Web framework Ruby on Rails is also a Ruby gem
  • 3. Why Ruby? ● Designed in mid-1990s by Yukihiro Matsamuto ● "I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language." ● Goal is Very Nice, but what’s Ruby?
  • 4. What’s Ruby? Ruby is dynamic, reflective, object-oriented general purpose programming language. Also, it is very user friendly(after some time). Also, let’s see examples and welcome to check out Wikipedia!
  • 5. Some examples Everything is an object -199.abs # => 199 "ice is nice".length # => 11 "ruby is cool.".index("u") # => 1 "Nice Day Isn't It?".downcase.split("").uniq.sort.join # => " '?acdeinsty" Classes are never closed # re-open Ruby's Time class class Time def yesterday self - 86400 end end today = Time.now # => 2013-09-03 16:09:37 +0300 yesterday = today.yesterday # => 2013-09-02 16:09:37 +0300
  • 6. Some examples Blocks and iterators { puts "Hello, World!" } # note the braces # or: do puts "Hello, World!" end array.each {|item| puts item } array.each_index {|index| puts "#{index}: #{array[index]}" } File.readlines('file.txt').each do |line| puts line end
  • 7. OK, what’s RoR? ● full stack framework ● makes use of ○ Model-View-Controller ○ Don’t Repeat Yourself ○ Active Record ○ RESTful routes ○ Fat Models Skinny Controllers ● first released on 2004, as extract from Basecamp
  • 9. RoR tools ● rails itself: ○ rails new ○ rails g (scaffold|model|controller|migration|...) ○ rails server ● rake, the Ruby make (for running tasks defined by RoR and you): ○ rake db:migrate ○ rake assets:precompile ○ rake somelib:sometask ● bundler, takes care of project specific gems, specified in Gemfile: ○ bundle install
  • 10. How to get started? ● Install RVM - much recommended! ● Install Ruby using RVM ● Install RubyGems using RVM ● Install your first gem - Rails (gem install smth) ● Now you have tools to start developing - but you need to run the app somehow..
  • 11. How to get started? Ways to run RoR apps: ● built in webserver - rails server ● Passenger module for Apache/Nginx (recommended) ● Unicorn webserver ● Puma webserver
  • 12. How do I build an app? Easy! rails new fabulousapp # create the app, done! cd fabulousapp rails g scaffold article # let’s have all at once … edit migration, define fields … rake db:migrate # oh, right, no DB defined rake routes # scaffold is good for you (add default, though) At this point, you can launch your app!
  • 13. Articles need comments Easy, just: ● create new scaffold: rails g comment ● add relation: ○ comment - belongs_to :article ○ article - has_many :comments (see plural form?) ● get the comments, e.g. in controller: class ArticlesController < ApplicationController def show @article = Article.find(params[:id]) @comments = @article.comments end ...
  • 14. We want to see comments! Each controller action should have an associated view (unless configured otherwise): so, for ArticlesController show action we’d have: app/views/articles/show.html.erb Response format can also be changed: class ArticlesController < ApplicationController def lazy_load @article = Article.find(params[:id]) @comments = @article.comments respond_with :js # Will look for app/views/articles/lazy_load.js.erb end ...
  • 15. We want to see comments! Views in Rails are layout based (controller defines layout): app/views/layouts/application.html.erb Here we see how: - stylesheets and javascripts are included - what variable tag looks like - where does controller response go to <!DOCTYPE html> <html> <head> <title>Fabulousapp</title> <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data- turbolinks-track" => true %> <%= csrf_meta_tags %> </head> <body> <%= yield %> </body> </html>
  • 16. Still no comments! Views can consist of single template: <div class="wrapper"> <div class="center_content"> <%= article.content %> <% if @comments.any? %> <div class="comments_placeholder"> …. Or, they can call other views as well: …. <% if @comments.any? %> <%= render partial: 'comment_form', locals: {article: @article} %>
  • 17. This is ugly! Rails use SCSS and CoffeeScript for styles and frontend scripts. One can always fall back to vanilla CSS and JS. Remember application.html.erb? <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> This will look for app/assets/javascripts/application.js You can define JS/CSS on action scope, as controller can define layout. Images referenced in CSS is stored in app/assets/images/
  • 18. What about bad guys? ● for certain actions you can set before_filter: class ArticlesController < ApplicationController before_filter :require_uber_user, :only => [:delete] def require_uber_user current_user.uber_user end ● CSRF token support by default ● few good auth gems available
  • 19. Is there a gem for …? ● Most likely, yes. ● AND, you get to rewrite them, if needed.
  • 20. My changes don’t work! Unless development environment variable is set up, Rails app will be run in it’s compiled state and won’t care about code or assets changes. To avoid it: - set the variable already, OR - touch tmp/restart.txt - rake assets:precompile
  • 21. Doing > Listening! Good luck! Questions?