Your SlideShare is downloading. ×
0
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Wprowadzenie do Ruby on Rails
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Wprowadzenie do Ruby on Rails

2,011

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,011
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ruby on Rails Wprowadzenie Klaudiusz Fabryczny, klodus@gmail. com Katowice, Spodek 2.0, 2007.10.13
  • 2. Ruby http: lIwww. 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.
  • 3. Ruby on Rails http: llwww. 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)
  • 4. Komponenty Ruby on Rails: - ActiveRecord, - ActionPack: - Actioncontroller, - ActionView, - ActionWebService, - ActiveSupport, - ActionMailer, - ActiveResource - REST
  • 5. Struktura aplikacji (niepełna): Spodek GPP controllers helpers models views conñg environments database. ymI environment. rb routes. rb db migrate O01_nazwa_migracji. rb doc lib taks log public images javascripts stylesheets script test tmp vendor plugins
  • 6. ActionPack http: //aplikacja/ adminledit_userI1024 MVC / home/ k/Spodek/ app/ controllers/ admin_controIler. rb class AdminControIler < AppIicationControIler 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 %>
  • 7. Active Record Klasa odpowiada tabeli bazodanowej instancja danej klasy konketnemu rekordowi w tabeli. Atrybut obiektu, polu w tabeli. MVC / home/ k/Spodek/ app/ models/ user. rb Tabela USeTS class User < ActiveRecord: :Base end
  • 8. Relacje "jeden do jednego" class Car < ActiveRecord: :Base Class Owner < ActiveRecord: :Base belongs_to : owner has_one : car end end
  • 9. “jeden do wielu" class Child < ActiveRecord: :Base class Mother < ActiveRecord: :Base belongs_to : mother has_many : children end end
  • 10. "wiele do wielu" m authors_books author_id Iii tirst_name book_id - i class Author < ActiveRecord: :Base Class Book < ActiveRecord: :Base has_and_belongs_to_many : books has_and_belongs_to_many : authors end end
  • 11. @book = Book. find(1 O24) @authors = @book. authors @author = Author. find(2048) @books_of_author = @author. books
  • 12. "Findery" @user = User. find_by_login_and_password(login, password) @user = User. find(: first, :conditions = >["Iogin = ? and password = ?", login, password ] ) @order = Order. find_by_sql("select id, name where id = 21")
  • 13. Walidacja class User < ActiveRecord: :Base validates_uniqueness_of zlogin, :message = >"Login musi być unikalny ll! " vaIidates_confirmation_of : password validates_format_of : length, :with = > l^d+(m| cm)l validates_length_of zname, :maximum = >30 end
  • 14. "Callback'i" class User < ActiveRecord : :Base before_destroy : check_rights def check_rights # kod metody end end
  • 15. Paginator def list_products @product_pages, @products = paginate (zproducts, :order_by = >'name') end <%= pagination_links(@product_pages) °/ o>
  • 16. Layout'y class AdminControIler < AppIicationControIler layout "admin" end class UserControlIer < AppIicationControIler layout "user", :except = > [zrss] end
  • 17. Migracja class CreateUsers < ActiveRecord: :Migration def self. up create_table "users" do | f| f. column "f_name", :string f. column "I_name", :string end end def self. down drop_table "users" end end
  • 18. Rake rake db: migrate rake db: migrate VERSION = 12 rake tmp: clear rake log: clear rake -T
  • 19. AJAX <head> <%= javascript_include_tag "prototype" %> <Ihead> <%= Iink_to_remote ("Show", :update = >"mydiv", :url = > { : action = >:update_div} ) %> <div id= "mydiv">Zmień mnie<ldiv>
  • 20. Konsola ruby script/ concole »> u = Dog. find_by_name("Mantas") »> u. id = > 1 »> u. rasa = "Spaniel" »> u. save »> d = Dog. find(12) »> d. destroy
  • 21. Linki: http: lIwww. ruby-lang. org http: llwww. rubyonrails. com http: llwww.37signals. com http: llwww. basecamphq. com http: llwww. railsenvy. com http: llwww. rubyinside. com http: llrailscasts. com http: llwww. pragprog. com http: lIwiki. rubyonrails. org/ rails/ pages/ Plugins
  • 22. 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.
  • 23. Dziękuję za uwagę : pytania = > "klodus@gmail. com"

×