• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Wprowadzenie do Ruby on Rails

on

  • 2,917 views

 

Statistics

Views

Total Views
2,917
Views on SlideShare
2,469
Embed Views
448

Actions

Likes
0
Downloads
28
Comments
0

8 Embeds 448

http://spodek20.pl 351
http://www.spodek20.pl 73
http://www.barcamp.pl 17
http://planeta.barcamp.pl 3
http://feeds.feedburner.com 1
http://barcamp.pl 1
http://www.slideshare.net 1
http://alfa.spodek20.pl 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Wprowadzenie do Ruby on Rails Wprowadzenie do Ruby on Rails Presentation Transcript

    • Ruby on Rails Wprowadzenie Klaudiusz Fabryczny, klodus@gmail.com Katowice, Spodek 2.0, 2007.10.13
    • Ruby http://www.ruby-lang.org - twórca: Yukihiro Matsumoto, “Matz” - cechy języka: - darmowy, - o otwartym kodzie, - przenośny, - VHLL, - interpretowany, - w pełni objektowy, - dynamiczny, - łatwy do nauki, - zwięzły, - czytelny, - rozszerzalny, - aktywna społeczność, - reflection, - metaprograming.
    • Ruby on Rails http://www.rubyonrails.com - twórca: David Heinemeier Hansson - cechy framework'u : - darmowy, - o otwartym kodzie, - web'owy, - wysoce produktywny, - wspiera Ajax'a, - posiada wbudowany webserver WEBrick, - system budowania rake, - mechanizm migracji, - ORM (Object Relation Mapping), - interaktywna konsola, - architektura MVC (Model – Viev – Controller), - “filozofia”: - DRY (Don't Repeat Yourself), - CoC (Convention over Configuration)
    • Komponenty Ruby on Rails: - ActiveRecord, - ActionPack: - ActionController, - ActionView, - ActionWebService, - ActiveSupport, - ActionMailer, --------------------------- - ActiveResource - REST
    • Struktura aplikacji (niepełna): Spodek app controllers helpers models views config environments database.yml environment.rb routes.rb db migrate 001_nazwa_migracji.rb doc lib taks log public images javascripts stylesheets script test tmp vendor plugins
    • ActionPack http://aplikacja/admin/edit_user/1024 MVC /home/k/Spodek/app/controllers/admin_controller.rb class AdminController < ApplicationController def edit_user # kod metody end end MVC /home/k/Spodek/app/views/admin/edit_user.rhtml < % form_tag do |form| %> <%= render :partial =>”user” %> <%= submit_tag “Edytuj” %> <% end %>
    • ActiveRecord Klasa odpowiada tabeli bazodanowej Instancja danej klasy konketnemu rekordowi w tabeli. Atrybut obiektu, polu w tabeli. MVC Tabela users /home/k/Spodek/app/models/user.rb class User < ActiveRecord::Base end
    • Relacje “jeden do jednego” class Car < ActiveRecord::Base Class Owner < ActiveRecord::Base belongs_to :owner has_one :car end end
    • “jeden do wielu” class Child < ActiveRecord::Base class Mother < ActiveRecord::Base belongs_to :mother has_many :children end end
    • “wiele do wielu” class Author < ActiveRecord::Base Class Book < ActiveRecord::Base c l has_and_belongs_to_many :books has_and_belongs_to_many :authors a end end
    • @book = Book.find(1024) @authors = @book.authors @author = Author.find(2048) @books_of_author = @author.books
    • “Findery” @user = User.find_by_login_and_password(login, password) @user = User.find(:first, :conditions =>[“login = ? and password = ?”, login, password ] ) @order = Order.find_by_sql(“select id, name where id = 21”)
    • Walidacja class User < ActiveRecord::Base validates_uniqueness_of :login, :message =>”Login musi być unikalny !!!” validates_confirmation_of :password validates_format_of :length, :with => /^d+(m|cm)/ validates_length_of :name, :maximum =>30 end
    • “Callback'i” class User < ActiveRecord::Base before_destroy :check_rights def check_rights # kod metody end end
    • Paginator def list_products @product_pages, @products = paginate (:products, :order_by =>'name') end <%= pagination_links(@product_pages) %>
    • Layout'y class AdminController < ApplicationController layout “admin” end class UserController < ApplicationController layout “user”, :except => [:rss] end
    • Migracja class CreateUsers < ActiveRecord::Migration def self.up create_table “users” do |f| f.column “f_name”, :string f.column “l_name”, :string end end def self.down drop_table “users” end end
    • Rake rake db:migrate rake db:migrate VERSION = 12 rake tmp:clear rake log:clear rake -T
    • AJAX <head> <%= javascript_include_tag “prototype” %> </head> <%= link_to_remote (“Show”, :update =>”mydiv”, :url => { :action =>:update_div} ) %> <div id=”mydiv”>Zmień mnie</div>
    • Konsola ruby script/concole >>> u = Dog.find_by_name(“Mantas”) >>> u.id => 1 >>> u.rasa = “Spaniel” >>> u.save >>> d = Dog.find(12) >>> d.destroy
    • Linki: http://www.ruby-lang.org http://www.rubyonrails.com http://www.37signals.com http://www.basecamphq.com http://www.railsenvy.com http://www.rubyinside.com http://railscasts.com http://www.pragprog.com http://wiki.rubyonrails.org/rails/pages/Plugins
    • Książki: - Agile Web Development with Rails: Second Edition, 2nd Edition, - Practices of an Agile Developer, - Programming Ruby: The Pragmatic Programmer's Guide, 2nd Edition, - Rails Recipes, - From Java To Ruby: Things Every Manager Should Know, - Learn to Program (Ruby), - Enterprise Integration with Ruby, - Rails for PHP Developers, - Rails for Java Developers, - Beginning Ruby: From Novice to Professional, - Practical Ruby Gems, - Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional.
    • Dziękuję za uwagę :pytania => “klodus@gmail.com”