SlideShare a Scribd company logo
Rails
geležinkelio romantika ir buitis

Adomas Sliužinskas @ VilniusRB, 2014-03-01
Rails
● Ruby frameworkas
● Skirtas web aplikacijoms
● Su nuomone: Rails way
The Rails Way
Yra “geriausi” būdai.
Jie geresni už alternatyvas.
Žinote patternų kitose kalbose?
Turite įpročių?
Taikote juos Railsuose?
Rails: buzzwords!
● DRY: Don’t Repeat Yourself
● CoC: Convention over Configuration
Rails: buzzwords!
● DRY: Don’t Repeat Yourself
● CoC: Convention over Configuration
● MVC: Model View Controller
● REST: REpresentational State Transfer
● KISS: Keep It Simple Stupid
Rails: buzzwords!
● DRY: Don’t Repeat Yourself
● CoC: Convention over Configuration
●
●
●
●

MVC: Model View Controller
REST: REpresentational State Transfer
KISS: Keep It Simple Stupid
TDD, BDD…
Rails: buzzwords!
● DRY: Don’t Repeat Yourself
● CoC: Convention over Configuration
●
●
●
●
●
●

MVC: Model View Controller
REST: REpresentational State Transfer
KISS: Keep It Simple Stupid
TDD, BDD…
ALL the best practices!
OMGWTFBBQ!
Rails aplikacijų kūrimas
87%* Ruby on Rails tutorialų/knygų žada:
● išmoksite greitai
● išmoksite lengvai
● aplikacijas kursite greitai
● laimingas developeris
● protingas developeris, nes best practices!

* man taip atrodo
Rails aplikacijų kūrimas
87%* Ruby on Rails tutorialų/knygų žada:
● išmoksite greitai
● išmoksite lengvai
● aplikacijas kursite greitai
● laimingas developeris
● protingas developeris, nes best practices!
ORLY?
* grynai asmeninė nuomonė
Rails aplikacijų kūrimas
87%* Ruby on Rails tutorialų/knygų žada:
● išmoksite greitai
● išmoksite lengvai
● aplikacijas kursite greitai
● laimingas developeris
● protingas developeris, nes best practices!
ORLY?
* grynai asmeninė nuomonė
Rails aplikacijų kūrimas
87%* Ruby on Rails tutorialų/knygų žada:
● išmoksite greitai
● išmoksite lengvai
● aplikacijas kursite greitai
● laimingas developeris
● protingas developeris, nes best practices!
ORLY?
* grynai asmeninė nuomonė
Rails aplikacijų kūrimas
87%* Ruby on Rails tutorialų/knygų žada:
● išmoksite greitai
● išmoksite lengvai
● aplikacijas kursite greitai
● laimingas developeris
● protingas developeris, nes best practices!
ORLY?
* grynai asmeninė nuomonė
Rails: out of the box
●
●
●
●
●

Full stack web framework
jQuery
i18n
paruošta testams
daug magijos

Ir dar daug visko. Labai daug.
Rails: not included in the box
● Authentication
● Backwards compatibility
Rails: not included in the box
● Authentication. Nes daug gemų.
● Backwards compatibility. Nes progresas.
Rails aplikacijų kūrimui reikės:
1. HTML
2. CSS
3. Ruby pagrindai
Rails aplikacijų kūrimui reikės:
1. HTML
2. CSS
3. Ruby pagrindai
4. Rails
5. ????
6. PROFIT!!!
Rails aplikacijų kūrimui reikės:
1. HTML
2. CSS
3. Ruby pagrindai

NOT!

4. Rails
5. ????
6. PROFIT!!!
Totalizatorius!!!

Rubistai, NEPASAKINĖKIT!

Kiek punktų bus pristatyme?
4. MVC

http://darynholmes.files.wordpress.com/2008/03/routinginrails.png
5. Routes
root :to => 'home#index'
match ‘admin’ => ‘admin/users#index’, :as => :admin
resources :comments, :except => [:new, :show]

routes.rb
6. REST
GET
POST

“/pages”
“/pages”

GET
“/pages/1”
PUT
“/pages/1”
DELETE “/pages/1”
GET
GET

# => index
# => create
# => show
# => update
# => destroy

“/pages/new”
# => new
“/pages/1/edit” # => edit
7. ORM: ActiveRecord (models)
●
●
●
●
●
●

CRUD
Validations
Callbacks (:before, :after, :around)
Migrations (via Rake)
Query interface
Associations
8. ActionView (views & helpers)
● Layouts
● Templates
● Partials (subtemplates)
● Template caching
● Helpers
○ FormHelper
■ Remote forms: ajax forms out of the box!!!1
○ Lyginant su ^ visa kita nesvarbu
9. Asset pipeline
● CSS
● JS
● Paveikslėliai
● Konkatanacija
9. Asset pipeline
● CSS
● JS
● Paveikslėliai
● Konkatanacija
● Minifikacija
9. Asset pipeline
● CSS
● JS
● Paveikslėliai
● Konkatanacija
● Minifikacija
● Suspaudimas
9. Asset pipeline
● CSS
● JS
● Paveikslėliai
●
●
●
●

Konkatanacija
Minifikacija
Suspaudimas
Preprocesinimas
9. Asset pipeline
● CSS
● JS
● Paveikslėliai
●
●
●
●
●

Konkatanacija
Minifikacija
Suspaudimas
Preprocesinimas
Referendumas
9. Asset pipeline
● CSS
● JS
● Paveikslėliai
●
●
●
●
●

Konkatanacija
Minifikacija
Suspaudimas
Preprocesinimas?
Referendumas
9. Asset pipeline
● CSS, SASS, SCSS, LESS
● JS, CoffeeScript
● Paveikslėliai
●
●
●
●

Konkatanacija
Minifikacija
Suspaudimas
Preprocesinimas?
10. CSS framework
Pagal nutylėjimą: SASS
Realiai: SCSS
$color_link: #0033cc;
a {
text-decoration: none;
&:link, &:visited {
color: $color_link;
}
}
11. DB migracijos
class CreatePermissions < ActiveRecord::Migration
def self.up
create_table :permissions do |t|
t.integer :user_id
t.string :type
end
add_index :user_id
end
def self.down
drop_table :permissions
end
end
12. Rails komandinė eilutė
$ rails new
$ rails server
$ rails generate
$ rails console
12. Rails generatoriai
$ rails generate controller CreditCard open debit credit close
$ rails g

controller CreditCard open debit credit close

$ rails g model user email:index country_id:integer:index
$ rails g scaffold user email:string:index country_id:integer:index
13. Rake
$ rake db:create
...
$ rails generate migration
...
$ rake db:migrate

$ rake assets:precompile
$ rake routes
$ rake --tasks
14. Template engine: ERB
<% items.each do |item| %>
<li><%= item.title %></li>
<% end %>
14. Template engine: ERB
<% items.each do |item| %>
<li><%= item.title %></li>
<% end %>
vs. PHP:

<? foreach($items as $item) { ?>
<li><? echo $item[‘title’]; ?></li>
<? } ?>
14. Template engine: ERB
<% items.each do |item| %>
<li><%= item.title %></li>
<% end %>
menu.html.erb vs. menu.js.erb

$(document).ready(function() {
App.load(<%= data.to_json %>);
});
14a. ERB == PHP?
<% items.each do |item| %>
<li><%= item.title %></li>
<% end %>
vs. PHP:

<? foreach($items as $item) { ?>
<li><? echo $item[‘title’]; ?></li>
<? } ?>
14b. Slim
- if ad.active?
#ad.jumbotron.text-center
h1 = ad.title
p.head
a href=”/faq”
| FAQ
#footer
| BBQ
14b. Slim vs. ERB
- if ad.active?
#ad.fu.bar

<% if ad.active? %>
<div id=”ad” class=”fu bar”>

h1 = ad.title

<h1><%= ad.title %></h1>

p.head

<p class=”head”>

a href=”/faq”
| FAQ
#footer
| BBQ

<a href=”/faq”>FAQ</a>
</p>
</div>
<% end %>
<div id=”footer”>BBQ</div>
15. Gem’ai
RubyGems: paketų manageris
Gem: paketas/biblioteka
gem 'mysql2'
Rails: Gemfile

$ bundle install
16. RVM arba rbenv
Ruby versijų manageris

$ rvm install jruby-1.7.9
$ rvm --default use 2.1.1
17. Unix OS
Windowsai nelabai:
● RVM. Alternatyva - Pik
● Command line
● Git
● SSH
● bendruomenės supportas...
18. YAML
development: &development
adapter: mysql2
database: doge_crm
username: such_root
password: much_security_wow!1
production:
<<: *development
adapter: pg
routes.rb
19. Environments
● development
● test
● production
● duomenų bazės
● performance
● aplikacijos logikoje
- if Rails.env.production?
javascript:
/ Google Analytics code
20. “Jūsų VPS”: deployinimas
Shared hosting? NOPE!
20. “Jūsų VPS”: deployinimas
Shared hosting? NOPE!
Pradžiai: Heroku
20. “Jūsų VPS”: deployinimas
Shared hosting? NOPE!
Pradžiai: Heroku
Galima su Rake
20. “Jūsų VPS”: deployinimas
Shared hosting? NOPE!
Pradžiai: Heroku
Galima su Rake
Geriausia: Capistrano
20. “Jūsų VPS”: deployinimas
Shared hosting? NOPE!
Pradžiai: Heroku
Galima su Rake
Geriausia: Capistrano…

21. Capistrano
20. “Jūsų VPS”: deployinimas
FTP?
20. “Jūsų VPS”: deployinimas
FTP?
Įmanoma, bet…

22. git
23. Duomenų bazių skirtumai
MySQL vs. PostgreSQL vs. SQLite
SQLite nepalaiko...
a) ADD COLUMN
b) ALTER COLUMN
c) DROP COLUMN
23. Duomenų bazių skirtumai
MySQL vs. PostgreSQL vs. SQLite
SQLite nepalaiko...
a) ADD COLUMN
b) ALTER COLUMN
c) DROP COLUMN
Testai: buzzwords
TDD: Test Driven Development?
BDD: Behaviour Driven Development?
CI: Continuous Integration?
Testai: tipai
Unit tests?
Functional tests?
Integration tests?
Testai: tipai
Unit tests?
Functional tests?
Integration tests?
How about no tests? (trollface)
Testai: tipai
Unit tests?
Functional tests?
Integration tests?
How about no tests? (trollface)
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
24. Test::Unit vs. RSpec
Test::Unit
● apie kodą
● assert that X predicate Y

RSpec
● apie objektus
● X should Y

Išsamiau:
http://programmers.stackexchange.com/questions/27328/rspec-vs-testunit-in-rails#answer-27406
25. Fixtures
john:
first_name: John
last_name: Doe
describe "#full_name" do
it "has first and last name" do
user = users(:john)
user.full_name.should eql("John Doe")
end
end
25a. Fixtures… yra blogis
● iš kur ir kaip atsirado user?
● ar tikrai kažkas kažkur kode nustatė
reikšmes?
describe "#full_name" do
it "has first and last name" do
user = users(:john)
user.full_name.should eql("John Doe")
end
end
25b. Factories vietoj Fixtures
factory :john do
first_name "John"
last_name "Doe"
describe "#full_name" do
it "has first and last name" do
@user = build(:user,
first_name: “Bruce”, last_name: “Willis”)
@user.full_name.should eql(“Bruce Willis”)
end
end
26. Mocks/stubs
Nes unit testing against database is wrong*
Stub: nustato objekto metodo grąžinamą
reikšmę
Mock: stub su metodo iškvietimo lūkesčiais

* because reasons
27. Cucumber
Integracinis/acceptance testavimas
Terminai:
Gherkin: Cucumber DSL, business readable
Capybara: gem’as, palengvinantis interakcijas
su naršykle(-ėmis)
28. Background tasks
●
●
●
●
●

Emailai
Importas/eksportas
Ilgai trunkančios užduotys
Schedulinamos užduotys
crontab aplikacijos viduje

Gem’ai:
● Sidekiq
● DelayedJob
● Resque
29. Debugging
Interaktyvus ruby debugeris: pry
Javascript analogas: debugger;
1. Gemfile: gem ‘pry’
2. $ bundle install
3. kode: binding.pry
4. užklausa naršyklėje/konsolėje
5. magija: railsų serverio lange
42. Failų struktūra
Interaktyvi dalis, kiek galima į skaidres žiūrėt :)
Klausimai!

Čia yra vieta jūsų (Ruby on Rails) problemoms.
Ačiū!
@adomas_s
adomas.sliuzinskas@gmail.com

* neturiu katinuko, tai bulvė
** romantika included
42 Rails developerio įrankiai
1. HTML

11. DB migracijos

21. Capistrano

2. CSS

12. Rails command line

22. git

3. Ruby pagrindai

13. Rake

23. DB niuansai

4. MVC

14. ERB/Slim

24. Test::Unit/RSpec

5. Routes

15. Gems

25. Factories

6. REST

16. RVM/rbenv

26. Mocks/stubs

7. ActiveRecord

17. Unix OS

27. Cucumber

8. ActionView

18. YAML

28. Background tasks

9. Asset pipeline

19. Environments

29. Debugging

10. CSS framework

20. Serverio priežiūra

42. Failų struktūra

More Related Content

Viewers also liked

Mgt last assignment
Mgt last assignmentMgt last assignment
Mgt last assignment
Asra Hameed
 
Metacognition During the Lesson
Metacognition During the LessonMetacognition During the Lesson
Metacognition During the Lesson
jonnagrossman
 
Techno assignment 3 marks
Techno assignment 3 marksTechno assignment 3 marks
Techno assignment 3 marks
Asra Hameed
 
FSBS Presentation 2015
FSBS Presentation 2015FSBS Presentation 2015
FSBS Presentation 2015Ana Maria Eder
 
Etapas del niño
Etapas del niñoEtapas del niño
Etapas del niño
Janii Corona Valadez
 
Media gallery9
Media gallery9Media gallery9
Media gallery9
seongju son
 
Evaluation Question 2
Evaluation Question 2Evaluation Question 2
Evaluation Question 2Melisahasan
 
Encyclopedia Brown and the Case of the Slippery Salamander story slides
Encyclopedia Brown and the Case of the Slippery Salamander story slidesEncyclopedia Brown and the Case of the Slippery Salamander story slides
Encyclopedia Brown and the Case of the Slippery Salamander story slides
deturner4
 
Theres a better way to do business in our Industry
Theres a better way to do business in our IndustryTheres a better way to do business in our Industry
Theres a better way to do business in our Industry
Carlos BullynationTv
 
Your finance center webinar
Your finance center webinarYour finance center webinar
Your finance center webinarWilliam Moore
 
Assistive technology
Assistive technologyAssistive technology
Assistive technologyMatt Graham
 
Presentation1
Presentation1Presentation1
Presentation1Trisnaa
 
Sb gwz-realtor program
Sb gwz-realtor programSb gwz-realtor program
Sb gwz-realtor program
William Moore
 

Viewers also liked (14)

Mgt last assignment
Mgt last assignmentMgt last assignment
Mgt last assignment
 
Tap company profile english
Tap company profile englishTap company profile english
Tap company profile english
 
Metacognition During the Lesson
Metacognition During the LessonMetacognition During the Lesson
Metacognition During the Lesson
 
Techno assignment 3 marks
Techno assignment 3 marksTechno assignment 3 marks
Techno assignment 3 marks
 
FSBS Presentation 2015
FSBS Presentation 2015FSBS Presentation 2015
FSBS Presentation 2015
 
Etapas del niño
Etapas del niñoEtapas del niño
Etapas del niño
 
Media gallery9
Media gallery9Media gallery9
Media gallery9
 
Evaluation Question 2
Evaluation Question 2Evaluation Question 2
Evaluation Question 2
 
Encyclopedia Brown and the Case of the Slippery Salamander story slides
Encyclopedia Brown and the Case of the Slippery Salamander story slidesEncyclopedia Brown and the Case of the Slippery Salamander story slides
Encyclopedia Brown and the Case of the Slippery Salamander story slides
 
Theres a better way to do business in our Industry
Theres a better way to do business in our IndustryTheres a better way to do business in our Industry
Theres a better way to do business in our Industry
 
Your finance center webinar
Your finance center webinarYour finance center webinar
Your finance center webinar
 
Assistive technology
Assistive technologyAssistive technology
Assistive technology
 
Presentation1
Presentation1Presentation1
Presentation1
 
Sb gwz-realtor program
Sb gwz-realtor programSb gwz-realtor program
Sb gwz-realtor program
 

Similar to Rails: geležinkelio romantika ir buitis

ERb alternatyvos
ERb alternatyvosERb alternatyvos
ERb alternatyvos
Vidmantas Kabošis
 
Say Hello to TypeScript (LT)
Say Hello to TypeScript (LT)Say Hello to TypeScript (LT)
Say Hello to TypeScript (LT)
Paulius Mačiulis
 
Ruby on rails @ Tobulėtuvė
Ruby on rails @ TobulėtuvėRuby on rails @ Tobulėtuvė
Ruby on rails @ Tobulėtuvė
Vidmantas Kabošis
 
Simonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiai
Simonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiaiSimonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiai
Simonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiai
tobuletuve
 
R language presentation
R language presentationR language presentation
R language presentationkafka399
 

Similar to Rails: geležinkelio romantika ir buitis (7)

ERb alternatyvos
ERb alternatyvosERb alternatyvos
ERb alternatyvos
 
Say Hello to TypeScript (LT)
Say Hello to TypeScript (LT)Say Hello to TypeScript (LT)
Say Hello to TypeScript (LT)
 
Ruby on rails @ Tobulėtuvė
Ruby on rails @ TobulėtuvėRuby on rails @ Tobulėtuvė
Ruby on rails @ Tobulėtuvė
 
Simonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiai
Simonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiaiSimonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiai
Simonas Vareikis - Web ir mobile aplikacijų kūrimo eiga bei įrankiai
 
R language presentation
R language presentationR language presentation
R language presentation
 
Audrys Kažukauskas
Audrys KažukauskasAudrys Kažukauskas
Audrys Kažukauskas
 
Rimantas Liubertas
Rimantas LiubertasRimantas Liubertas
Rimantas Liubertas
 

Rails: geležinkelio romantika ir buitis

  • 1. Rails geležinkelio romantika ir buitis Adomas Sliužinskas @ VilniusRB, 2014-03-01
  • 2. Rails ● Ruby frameworkas ● Skirtas web aplikacijoms ● Su nuomone: Rails way
  • 3. The Rails Way Yra “geriausi” būdai. Jie geresni už alternatyvas. Žinote patternų kitose kalbose? Turite įpročių? Taikote juos Railsuose?
  • 4.
  • 5. Rails: buzzwords! ● DRY: Don’t Repeat Yourself ● CoC: Convention over Configuration
  • 6. Rails: buzzwords! ● DRY: Don’t Repeat Yourself ● CoC: Convention over Configuration ● MVC: Model View Controller ● REST: REpresentational State Transfer ● KISS: Keep It Simple Stupid
  • 7. Rails: buzzwords! ● DRY: Don’t Repeat Yourself ● CoC: Convention over Configuration ● ● ● ● MVC: Model View Controller REST: REpresentational State Transfer KISS: Keep It Simple Stupid TDD, BDD…
  • 8. Rails: buzzwords! ● DRY: Don’t Repeat Yourself ● CoC: Convention over Configuration ● ● ● ● ● ● MVC: Model View Controller REST: REpresentational State Transfer KISS: Keep It Simple Stupid TDD, BDD… ALL the best practices! OMGWTFBBQ!
  • 9. Rails aplikacijų kūrimas 87%* Ruby on Rails tutorialų/knygų žada: ● išmoksite greitai ● išmoksite lengvai ● aplikacijas kursite greitai ● laimingas developeris ● protingas developeris, nes best practices! * man taip atrodo
  • 10. Rails aplikacijų kūrimas 87%* Ruby on Rails tutorialų/knygų žada: ● išmoksite greitai ● išmoksite lengvai ● aplikacijas kursite greitai ● laimingas developeris ● protingas developeris, nes best practices! ORLY? * grynai asmeninė nuomonė
  • 11. Rails aplikacijų kūrimas 87%* Ruby on Rails tutorialų/knygų žada: ● išmoksite greitai ● išmoksite lengvai ● aplikacijas kursite greitai ● laimingas developeris ● protingas developeris, nes best practices! ORLY? * grynai asmeninė nuomonė
  • 12. Rails aplikacijų kūrimas 87%* Ruby on Rails tutorialų/knygų žada: ● išmoksite greitai ● išmoksite lengvai ● aplikacijas kursite greitai ● laimingas developeris ● protingas developeris, nes best practices! ORLY? * grynai asmeninė nuomonė
  • 13. Rails aplikacijų kūrimas 87%* Ruby on Rails tutorialų/knygų žada: ● išmoksite greitai ● išmoksite lengvai ● aplikacijas kursite greitai ● laimingas developeris ● protingas developeris, nes best practices! ORLY? * grynai asmeninė nuomonė
  • 14. Rails: out of the box ● ● ● ● ● Full stack web framework jQuery i18n paruošta testams daug magijos Ir dar daug visko. Labai daug.
  • 15. Rails: not included in the box ● Authentication ● Backwards compatibility
  • 16. Rails: not included in the box ● Authentication. Nes daug gemų. ● Backwards compatibility. Nes progresas.
  • 17. Rails aplikacijų kūrimui reikės: 1. HTML 2. CSS 3. Ruby pagrindai
  • 18. Rails aplikacijų kūrimui reikės: 1. HTML 2. CSS 3. Ruby pagrindai 4. Rails 5. ???? 6. PROFIT!!!
  • 19. Rails aplikacijų kūrimui reikės: 1. HTML 2. CSS 3. Ruby pagrindai NOT! 4. Rails 5. ???? 6. PROFIT!!!
  • 22. 5. Routes root :to => 'home#index' match ‘admin’ => ‘admin/users#index’, :as => :admin resources :comments, :except => [:new, :show] routes.rb
  • 23. 6. REST GET POST “/pages” “/pages” GET “/pages/1” PUT “/pages/1” DELETE “/pages/1” GET GET # => index # => create # => show # => update # => destroy “/pages/new” # => new “/pages/1/edit” # => edit
  • 24. 7. ORM: ActiveRecord (models) ● ● ● ● ● ● CRUD Validations Callbacks (:before, :after, :around) Migrations (via Rake) Query interface Associations
  • 25. 8. ActionView (views & helpers) ● Layouts ● Templates ● Partials (subtemplates) ● Template caching ● Helpers ○ FormHelper ■ Remote forms: ajax forms out of the box!!!1 ○ Lyginant su ^ visa kita nesvarbu
  • 26. 9. Asset pipeline ● CSS ● JS ● Paveikslėliai ● Konkatanacija
  • 27. 9. Asset pipeline ● CSS ● JS ● Paveikslėliai ● Konkatanacija ● Minifikacija
  • 28. 9. Asset pipeline ● CSS ● JS ● Paveikslėliai ● Konkatanacija ● Minifikacija ● Suspaudimas
  • 29. 9. Asset pipeline ● CSS ● JS ● Paveikslėliai ● ● ● ● Konkatanacija Minifikacija Suspaudimas Preprocesinimas
  • 30. 9. Asset pipeline ● CSS ● JS ● Paveikslėliai ● ● ● ● ● Konkatanacija Minifikacija Suspaudimas Preprocesinimas Referendumas
  • 31. 9. Asset pipeline ● CSS ● JS ● Paveikslėliai ● ● ● ● ● Konkatanacija Minifikacija Suspaudimas Preprocesinimas? Referendumas
  • 32. 9. Asset pipeline ● CSS, SASS, SCSS, LESS ● JS, CoffeeScript ● Paveikslėliai ● ● ● ● Konkatanacija Minifikacija Suspaudimas Preprocesinimas?
  • 33. 10. CSS framework Pagal nutylėjimą: SASS Realiai: SCSS $color_link: #0033cc; a { text-decoration: none; &:link, &:visited { color: $color_link; } }
  • 34. 11. DB migracijos class CreatePermissions < ActiveRecord::Migration def self.up create_table :permissions do |t| t.integer :user_id t.string :type end add_index :user_id end def self.down drop_table :permissions end end
  • 35. 12. Rails komandinė eilutė $ rails new $ rails server $ rails generate $ rails console
  • 36. 12. Rails generatoriai $ rails generate controller CreditCard open debit credit close $ rails g controller CreditCard open debit credit close $ rails g model user email:index country_id:integer:index $ rails g scaffold user email:string:index country_id:integer:index
  • 37. 13. Rake $ rake db:create ... $ rails generate migration ... $ rake db:migrate $ rake assets:precompile $ rake routes $ rake --tasks
  • 38. 14. Template engine: ERB <% items.each do |item| %> <li><%= item.title %></li> <% end %>
  • 39. 14. Template engine: ERB <% items.each do |item| %> <li><%= item.title %></li> <% end %> vs. PHP: <? foreach($items as $item) { ?> <li><? echo $item[‘title’]; ?></li> <? } ?>
  • 40. 14. Template engine: ERB <% items.each do |item| %> <li><%= item.title %></li> <% end %> menu.html.erb vs. menu.js.erb $(document).ready(function() { App.load(<%= data.to_json %>); });
  • 41. 14a. ERB == PHP? <% items.each do |item| %> <li><%= item.title %></li> <% end %> vs. PHP: <? foreach($items as $item) { ?> <li><? echo $item[‘title’]; ?></li> <? } ?>
  • 42. 14b. Slim - if ad.active? #ad.jumbotron.text-center h1 = ad.title p.head a href=”/faq” | FAQ #footer | BBQ
  • 43. 14b. Slim vs. ERB - if ad.active? #ad.fu.bar <% if ad.active? %> <div id=”ad” class=”fu bar”> h1 = ad.title <h1><%= ad.title %></h1> p.head <p class=”head”> a href=”/faq” | FAQ #footer | BBQ <a href=”/faq”>FAQ</a> </p> </div> <% end %> <div id=”footer”>BBQ</div>
  • 44. 15. Gem’ai RubyGems: paketų manageris Gem: paketas/biblioteka gem 'mysql2' Rails: Gemfile $ bundle install
  • 45. 16. RVM arba rbenv Ruby versijų manageris $ rvm install jruby-1.7.9 $ rvm --default use 2.1.1
  • 46. 17. Unix OS Windowsai nelabai: ● RVM. Alternatyva - Pik ● Command line ● Git ● SSH ● bendruomenės supportas...
  • 47.
  • 48. 18. YAML development: &development adapter: mysql2 database: doge_crm username: such_root password: much_security_wow!1 production: <<: *development adapter: pg routes.rb
  • 49. 19. Environments ● development ● test ● production ● duomenų bazės ● performance ● aplikacijos logikoje - if Rails.env.production? javascript: / Google Analytics code
  • 50. 20. “Jūsų VPS”: deployinimas Shared hosting? NOPE!
  • 51. 20. “Jūsų VPS”: deployinimas Shared hosting? NOPE! Pradžiai: Heroku
  • 52. 20. “Jūsų VPS”: deployinimas Shared hosting? NOPE! Pradžiai: Heroku Galima su Rake
  • 53. 20. “Jūsų VPS”: deployinimas Shared hosting? NOPE! Pradžiai: Heroku Galima su Rake Geriausia: Capistrano
  • 54. 20. “Jūsų VPS”: deployinimas Shared hosting? NOPE! Pradžiai: Heroku Galima su Rake Geriausia: Capistrano… 21. Capistrano
  • 55. 20. “Jūsų VPS”: deployinimas FTP?
  • 56. 20. “Jūsų VPS”: deployinimas FTP? Įmanoma, bet… 22. git
  • 57. 23. Duomenų bazių skirtumai MySQL vs. PostgreSQL vs. SQLite SQLite nepalaiko... a) ADD COLUMN b) ALTER COLUMN c) DROP COLUMN
  • 58. 23. Duomenų bazių skirtumai MySQL vs. PostgreSQL vs. SQLite SQLite nepalaiko... a) ADD COLUMN b) ALTER COLUMN c) DROP COLUMN
  • 59. Testai: buzzwords TDD: Test Driven Development? BDD: Behaviour Driven Development? CI: Continuous Integration?
  • 60. Testai: tipai Unit tests? Functional tests? Integration tests?
  • 61. Testai: tipai Unit tests? Functional tests? Integration tests? How about no tests? (trollface)
  • 62. Testai: tipai Unit tests? Functional tests? Integration tests? How about no tests? (trollface) FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
  • 63. 24. Test::Unit vs. RSpec Test::Unit ● apie kodą ● assert that X predicate Y RSpec ● apie objektus ● X should Y Išsamiau: http://programmers.stackexchange.com/questions/27328/rspec-vs-testunit-in-rails#answer-27406
  • 64. 25. Fixtures john: first_name: John last_name: Doe describe "#full_name" do it "has first and last name" do user = users(:john) user.full_name.should eql("John Doe") end end
  • 65. 25a. Fixtures… yra blogis ● iš kur ir kaip atsirado user? ● ar tikrai kažkas kažkur kode nustatė reikšmes? describe "#full_name" do it "has first and last name" do user = users(:john) user.full_name.should eql("John Doe") end end
  • 66. 25b. Factories vietoj Fixtures factory :john do first_name "John" last_name "Doe" describe "#full_name" do it "has first and last name" do @user = build(:user, first_name: “Bruce”, last_name: “Willis”) @user.full_name.should eql(“Bruce Willis”) end end
  • 67. 26. Mocks/stubs Nes unit testing against database is wrong* Stub: nustato objekto metodo grąžinamą reikšmę Mock: stub su metodo iškvietimo lūkesčiais * because reasons
  • 68. 27. Cucumber Integracinis/acceptance testavimas Terminai: Gherkin: Cucumber DSL, business readable Capybara: gem’as, palengvinantis interakcijas su naršykle(-ėmis)
  • 69. 28. Background tasks ● ● ● ● ● Emailai Importas/eksportas Ilgai trunkančios užduotys Schedulinamos užduotys crontab aplikacijos viduje Gem’ai: ● Sidekiq ● DelayedJob ● Resque
  • 70. 29. Debugging Interaktyvus ruby debugeris: pry Javascript analogas: debugger; 1. Gemfile: gem ‘pry’ 2. $ bundle install 3. kode: binding.pry 4. užklausa naršyklėje/konsolėje 5. magija: railsų serverio lange
  • 71. 42. Failų struktūra Interaktyvi dalis, kiek galima į skaidres žiūrėt :)
  • 72. Klausimai! Čia yra vieta jūsų (Ruby on Rails) problemoms.
  • 74. 42 Rails developerio įrankiai 1. HTML 11. DB migracijos 21. Capistrano 2. CSS 12. Rails command line 22. git 3. Ruby pagrindai 13. Rake 23. DB niuansai 4. MVC 14. ERB/Slim 24. Test::Unit/RSpec 5. Routes 15. Gems 25. Factories 6. REST 16. RVM/rbenv 26. Mocks/stubs 7. ActiveRecord 17. Unix OS 27. Cucumber 8. ActionView 18. YAML 28. Background tasks 9. Asset pipeline 19. Environments 29. Debugging 10. CSS framework 20. Serverio priežiūra 42. Failų struktūra