SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
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?

Mais conteúdo relacionado

Mais procurados

Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - BasicEddie Kao
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Railsmithunsasidharan
 
Présentation jQuery pour débutant
Présentation jQuery pour débutantPrésentation jQuery pour débutant
Présentation jQuery pour débutantStanislas Chollet
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page ApplicationKMS Technology
 
Web application development with laravel php framework version 4
Web application development with laravel php framework version 4Web application development with laravel php framework version 4
Web application development with laravel php framework version 4Untung D Saptoto
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to RubyRanjith Siji
 
MariaDB Administrator 교육
MariaDB Administrator 교육 MariaDB Administrator 교육
MariaDB Administrator 교육 Sangmo Kim
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Percona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL ArchitecturesPercona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL ArchitecturesFrederic Descamps
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Introduction of MariaDB 2017 09
Introduction of MariaDB 2017 09Introduction of MariaDB 2017 09
Introduction of MariaDB 2017 09GOTO Satoru
 
Introduction to MariaDB
Introduction to MariaDBIntroduction to MariaDB
Introduction to MariaDBJongJin Lee
 

Mais procurados (20)

Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Présentation jQuery pour débutant
Présentation jQuery pour débutantPrésentation jQuery pour débutant
Présentation jQuery pour débutant
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
Ruby programming
Ruby programmingRuby programming
Ruby programming
 
MySQL - NDB Cluster
MySQL - NDB ClusterMySQL - NDB Cluster
MySQL - NDB Cluster
 
Web application development with laravel php framework version 4
Web application development with laravel php framework version 4Web application development with laravel php framework version 4
Web application development with laravel php framework version 4
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
MariaDB Administrator 교육
MariaDB Administrator 교육 MariaDB Administrator 교육
MariaDB Administrator 교육
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Percona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL ArchitecturesPercona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL Architectures
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Introduction of MariaDB 2017 09
Introduction of MariaDB 2017 09Introduction of MariaDB 2017 09
Introduction of MariaDB 2017 09
 
Introduction to MariaDB
Introduction to MariaDBIntroduction to MariaDB
Introduction to MariaDB
 

Destaque

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails PresentationJoost 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 Coursepeter_marklund
 
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 PresentationChanHan Hy
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on RailsJonathan 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
 

Destaque (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)
 

Semelhante a RoR (Ruby on Rails)

Introduction to rails
Introduction to railsIntroduction to rails
Introduction to railsGo Asgard
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On RailsSteve Keener
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsAlessandro DS
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
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
 
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 2013Brian Sam-Bodden
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Railsanides
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overviewThomas Asikis
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First MileGourab Mitra
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorialsunniboy
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfssusercd195b
 
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 2016Justin Gordon
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails FinalRobert Postill
 

Semelhante a 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
 

Último

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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?