SlideShare a Scribd company logo
Rails Introduction
for those who have heard a lot about it
Rails IntroductionRails Introduction
application structure
MVC
Model
 app/models/user.rb
class User < ActiveRecord::Base
end
class User < ActiveRecord::Base
attr_accessible :email, :password
validates :email, presence: true
end
class User < ActiveRecord::Base
attr_accessible :email, :password
validates :email, presence: true
has_many :blog_posts
end
Controller
app/controllers/users_controller.rb
class UsersController < ApplicationController
end
app/controllers/application_controller.rb
class UsersController < ApplicationController
def index
end
def show
end
def create
end
def edit
end
def update
end
def destroy
end
end
View
app/views/users/index.html.haml
Erb, HAML, Slim
http://html2haml.heroku.com
class UsersController < ApplicationController
def index
@users = User.all
end
end
­ @users.each do |user|
%h1= user.email
%h1= user.password
app/controllers/users_controller.rb
app/views/users/index.html.haml
assets
app/assets/javascripts
javascript, coffeescript
app/assets/stylesheets
CSS, SASS, LESS
app/assets/images
jpg, png, gif
decorators
app/decorators
gem 'draper'
class Student < ActiveRecord::Base
attr_accessible :first_name, :middle_name, :last_name
validates :email, presence: true
has_many :blog_posts
def fio
«#{first_name} #{middle_name} #{last_name}»
end 
def with_first_name(first_name)
User.find_by_first_name first_name
end
end
app/models/student.rb
decorators
app/decorators
gem 'draper'
class Student < ActiveRecord::Base
attr_accessible :first_name, :middle_name, :last_name
validates :email, presence: true
has_many :blog_posts
end
class StudentDecorator < Draper::Base
decorates :member
def fio
«#{model.first_name} #{model.middle_name} #{model.last_name}»
end 
def with_first_name(first_name)
User.find_by_first_name first_name
end
end
app/decorators/student_decorator.rb
uploaders
app/uploaders
gem 'carrierwave'
gem 'paperclip'
layouts
app/views/layouts/application.html.haml
%html
  %head
    %title SkyDance
    = stylesheet_link_tag    "bootstrap_and_overrides", :media => "all"
    = stylesheet_link_tag    "application", :media => "all"
    = javascript_include_tag "application"
    = csrf_meta_tags
  %body
    = yield
routes
config/routes.rb
Application.routes.draw do
  root :to => "welcome#index"
  match "admin" => "admins#login"
  get "schedule" => "lessons#schedule"
  resources :groups, :except => [:show, :index] do
    member do
      resources :lessons, :except => [:show, :index]
    end
  end
  resources :teachers do
    member do
      resources :photos, :except => [:show, :index, :edit] do
        collection do
          get 'admins'
        end
      end
    end
  end
end
Http-requests
● GET
● POST
● PUT
● DELETE
http-statuses
● 200
● 404
● 403
● 500
locales
КИРИЛЛИЦА
migrations
db/migrate
$ rails g migration add_sleep_to_my_life
db/migrate/add_sleep_to_my_life.rb
class AddSleepToMyLife < ActiveRecord::Migration
def change
add_column :my_lifes, :sleep, :fuck_you
add_column :table, :column_name, :column_type
end
end
db/migrate
$ rails g migration add_sleep_to_my_life
db/migrate
$ rails g migration add_sleep_to_my_life
tests
TDD — test­driven development 
http://travis­ci.org
http://coveralls.io
gem 'minitest'
tests
class UsersControllerTest < ApplicationController::TestCase
test «should get index» do
get :index
assert_response :success
end
end
test/functional/users_controller_test.rb
services
● http://travis­ci.org
● http://coveralls.io
● http://codeclimate.com
● http://github.com
thnx

More Related Content

What's hot

Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 
Rails engines in large apps
Rails engines in large appsRails engines in large apps
Rails engines in large apps
Enrico Teotti
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net Ajax
Jeff Blankenburg
 
Ajax control tool kit
Ajax control tool kitAjax control tool kit
Ajax control tool kit
Vidhi Patel
 

What's hot (20)

Rack
RackRack
Rack
 
Rails 5 – most effective features for apps upgradation
Rails 5 – most effective features for apps upgradationRails 5 – most effective features for apps upgradation
Rails 5 – most effective features for apps upgradation
 
Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layouts
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 
Let's do SPA
Let's do SPALet's do SPA
Let's do SPA
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 
5. servlets
5. servlets5. servlets
5. servlets
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
 
Rails engines in large apps
Rails engines in large appsRails engines in large apps
Rails engines in large apps
 
2310 b 03
2310 b 032310 b 03
2310 b 03
 
Rack
RackRack
Rack
 
Asp.net web api
Asp.net web apiAsp.net web api
Asp.net web api
 
Grant
GrantGrant
Grant
 
Application Server-less Web Applications - Serverless Toronto Meetup
Application Server-less Web Applications - Serverless Toronto Meetup Application Server-less Web Applications - Serverless Toronto Meetup
Application Server-less Web Applications - Serverless Toronto Meetup
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net Ajax
 
App Manifest
App ManifestApp Manifest
App Manifest
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
Ajax control tool kit
Ajax control tool kitAjax control tool kit
Ajax control tool kit
 
Rails Engines
Rails EnginesRails Engines
Rails Engines
 
Building custom APIs
Building custom APIsBuilding custom APIs
Building custom APIs
 

Viewers also liked

Correct the errors
Correct the errorsCorrect the errors
Correct the errors
jayaenglish
 
Facebook calender sep
Facebook calender sepFacebook calender sep
Facebook calender sep
wilsonrd1987
 
Zambian mining fund - Invest in Zambia
Zambian mining fund - Invest in Zambia Zambian mining fund - Invest in Zambia
Zambian mining fund - Invest in Zambia
Joe Beale
 
A guide to_mediumship_and_psychical_unfoldment__1920_
A guide to_mediumship_and_psychical_unfoldment__1920_A guide to_mediumship_and_psychical_unfoldment__1920_
A guide to_mediumship_and_psychical_unfoldment__1920_
psionicmind
 
Daily agri news letter 10 dec 2013
Daily agri news letter 10 dec 2013Daily agri news letter 10 dec 2013
Daily agri news letter 10 dec 2013
Rakhi Tips Provider
 
4th of July fireworks from Adler Planetarium
4th of July fireworks from Adler Planetarium4th of July fireworks from Adler Planetarium
4th of July fireworks from Adler Planetarium
dwhobrey
 

Viewers also liked (14)

Access Audit Report on Subash Bose Park, Ernakulam
Access Audit Report on Subash Bose Park, ErnakulamAccess Audit Report on Subash Bose Park, Ernakulam
Access Audit Report on Subash Bose Park, Ernakulam
 
Correct the errors
Correct the errorsCorrect the errors
Correct the errors
 
Potential business initiatives project update #1
Potential business initiatives  project update #1Potential business initiatives  project update #1
Potential business initiatives project update #1
 
Facebook calender sep
Facebook calender sepFacebook calender sep
Facebook calender sep
 
El síndrome del celibato Ramiro Perez Alvarez
El síndrome del celibato Ramiro Perez AlvarezEl síndrome del celibato Ramiro Perez Alvarez
El síndrome del celibato Ramiro Perez Alvarez
 
Zambian mining fund - Invest in Zambia
Zambian mining fund - Invest in Zambia Zambian mining fund - Invest in Zambia
Zambian mining fund - Invest in Zambia
 
Daily option news letter 25 july 2013
Daily option news letter 25 july 2013Daily option news letter 25 july 2013
Daily option news letter 25 july 2013
 
A guide to_mediumship_and_psychical_unfoldment__1920_
A guide to_mediumship_and_psychical_unfoldment__1920_A guide to_mediumship_and_psychical_unfoldment__1920_
A guide to_mediumship_and_psychical_unfoldment__1920_
 
My sql 5.6 master slave and master-master replication.step by step configurat...
My sql 5.6 master slave and master-master replication.step by step configurat...My sql 5.6 master slave and master-master replication.step by step configurat...
My sql 5.6 master slave and master-master replication.step by step configurat...
 
Daily agri news letter 10 dec 2013
Daily agri news letter 10 dec 2013Daily agri news letter 10 dec 2013
Daily agri news letter 10 dec 2013
 
Generación y separación
Generación y separaciónGeneración y separación
Generación y separación
 
4th of July fireworks from Adler Planetarium
4th of July fireworks from Adler Planetarium4th of July fireworks from Adler Planetarium
4th of July fireworks from Adler Planetarium
 
Генераторы газов Peak Scientific для приборов waters
Генераторы газов Peak Scientific для приборов watersГенераторы газов Peak Scientific для приборов waters
Генераторы газов Peak Scientific для приборов waters
 
St. Moritz Mckinley West Properties
St. Moritz Mckinley West PropertiesSt. Moritz Mckinley West Properties
St. Moritz Mckinley West Properties
 

Similar to Rails introduction

Rails Routing and URL design
Rails Routing and URL designRails Routing and URL design
Rails Routing and URL design
hiq5
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
Wen-Tien Chang
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
fiyuer
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
RORLAB
 
WebcampZG - Rails 4
WebcampZG - Rails 4WebcampZG - Rails 4
WebcampZG - Rails 4
shnikola
 
2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”
2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”
2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”
Yuichiro MASUI
 

Similar to Rails introduction (20)

Rupicon 2014 Action pack
Rupicon 2014 Action packRupicon 2014 Action pack
Rupicon 2014 Action pack
 
Rails Routing and URL design
Rails Routing and URL designRails Routing and URL design
Rails Routing and URL design
 
Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick Sutterer
 
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Migration from Rails2 to Rails3
Migration from Rails2 to Rails3Migration from Rails2 to Rails3
Migration from Rails2 to Rails3
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
WebcampZG - Rails 4
WebcampZG - Rails 4WebcampZG - Rails 4
WebcampZG - Rails 4
 
Merb
MerbMerb
Merb
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
 
2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”
2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”
2007/09/29 PHP to Rails - Webキャリアさん主催 ”PHPプログラマの為のRuby on Rails入門”
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
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 ...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
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
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 

Rails introduction