SlideShare ist ein Scribd-Unternehmen logo
1 von 19
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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入門”
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Rails introduction