1 / 26

Why rails?

Why rails?. Carlos Kirkconnell. Google. Happiness leads to Productivity Happiness Matters. “Programmers often feel joy when they can concentrate on the creative side of programming, so Ruby is designed to make programmers happy.” Yukihiro Matsumoto

thu
Download Presentation

Why rails?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Why rails? Carlos Kirkconnell

  2. Google

  3. Happiness leads to ProductivityHappiness Matters

  4. “Programmers often feel joy when they can concentrate on the creative side of programming, so Ruby is designed to make programmers happy.” Yukihiro Matsumoto “Ruby makes me happy because it allows me to write beautiful code. Aesthetics are strongly linked to enjoyment. It’s not just about getting the job done”.David Heinemeier Hansson

  5. “You can recognize truth by its beauty and simplicity. When you get it right, it is obvious that it is right.”Richard Feynman, Scientist

  6. Account.transaction(carlos, vera)do carlos.withdraw(100) vera.deposit(100)end

  7. classAccount< ActiveRecord::Baseend

  8. classAccount< ActiveRecord::Basevalidates_presence_of:subdomain,:name,:email_address,:passwordvalidates_uniqueness_of:subdomainvalidates_acceptance_of:terms_of_service,:on=>:createvalidates_confirmation_of:password,:email_address,:on=>:createend

  9. classProject< ActiveRecord::Basebelongs_to:portfoliohas_one:project_managerhas_many:milestoneshas_and_belongs_to_many:categoriesend

  10. classProject< ActiveRecord::Basebelongs_to:portfoliohas_one:project_manager,:class_name=>'Person'has_many:milestones,:dependent=>truehas_and_belongs_to_many:categories,:join_table=>'categorizations'end

  11. classAccount< ActiveRecord::Basehas_many:peopledodeffind_or_create_by_name(name) first_name, last_name = name.split last_name = last_name.join '' find_or_create_by_first_name_and_last_name(first_name, last_name)endendendperson =Account.find(:first).people.find_or_create_by_name("Gordon Freeman")person.first_name # => "Gordon"person.last_name # => "Freeman"

  12. classPost< ActiveRecord::Basehas_many:commentsendclassComment< ActiveRecord::Basedefself.search(query) find(:all,:conditions=>["body = ?", query])endend# SELECT * FROM comments WHERE post_id = 1 AND body = 'hi'greetings =Post.find(1).comments.search('hi')

  13. Real MVC Model Controller View .html View .xml View .atom

  14. class PhotographersController < ApplicationController# GET /photographers# GET /photographers.xmldef index @photographers = Photographer.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render:xml => @photographers }endend# GET /photographers/1# GET /photographers/1.xmldef show @photographer = Photographer.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render:xml => @photographer }endendend

  15. REST post get put delete HTTP create read update delete Active Record insert select update delete SQL

  16. RESTIt’s all about CRUD

  17. class Plan < ActiveRecord::Basehas_and_belongs_to_many:usersendclass User < ActiveRecord::Basehas_and_belongs_to_many:plansend

  18. class Plan < ActiveRecord::Basehas_many:subscriptionshas_many:users, :through => :subscriptionsendclass User < ActiveRecord::Basehas_many:subscriptionshas_many:plans, :through => :subscriptionsendclass Subscription < ActiveRecord::Basebelongs_to:userbelongs_to:planvalidates_presence_of:subscription_dateend

  19. Rails is RESTful by default • we get a free HTTP API • support for multiple mime types • simpler controllers • a better designed model

  20. All controllers have 7 actions • index => GET /photographers • show => GET /photographers/2 • new => GET /photographers/new • edit => GET /photographers/2/edit • create => POST /photographers • update => PUT /photographers/2 • delete => DELETE /photographers/2

  21. RJS and Ajax page[:graph].src = graph_path(@sync.burndown_id)page.replace_html :notice, flash[:notice]flash.discardpage.visual_effect :shake, :graph

  22. Rails invites you to... • write unit, functional & integration tests • use design patterns (Active Record, MVC, Observers) • work on different environments (development, test, production) • use migrations to manage db changes • validate forms • log errors

  23. At the cost of... • speed, ruby is interpreted... • no intellisense • no dialogs, wizards, or IDE • learning a lot about html and css

  24. Quesions?

More Related