Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Rails introduction

570 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Rails introduction

  1. 1. Rails Introduction for those who have heard a lot about it Rails IntroductionRails Introduction application structure
  2. 2. MVC
  3. 3. 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
  4. 4. 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
  5. 5. 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
  6. 6. assets app/assets/javascripts javascript, coffeescript app/assets/stylesheets CSS, SASS, LESS app/assets/images jpg, png, gif
  7. 7. 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
  8. 8. 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
  9. 9. uploaders app/uploaders gem 'carrierwave' gem 'paperclip'
  10. 10. 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
  11. 11. 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
  12. 12. Http-requests ● GET ● POST ● PUT ● DELETE
  13. 13. http-statuses ● 200 ● 404 ● 403 ● 500
  14. 14. locales КИРИЛЛИЦА
  15. 15. 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
  16. 16. tests TDD — test­driven development  http://travis­ci.org http://coveralls.io gem 'minitest'
  17. 17. tests class UsersControllerTest < ApplicationController::TestCase test «should get index» do get :index assert_response :success end end test/functional/users_controller_test.rb
  18. 18. services ● http://travis­ci.org ● http://coveralls.io ● http://codeclimate.com ● http://github.com
  19. 19. thnx

×