Your SlideShare is downloading. ×
0
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
mashraqi_farhan
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

mashraqi_farhan

554

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
554
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
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. Applied Ruby on Rails & AJAX An insight into the technology and principles behind a social networking community
    • 2. Who am I? <ul><li>Farhan Mashraqi (Frank Mash) </li></ul><ul><li>Developer for 7+ years </li></ul><ul><li>MySQL DBA </li></ul><ul><li>Community Member </li></ul><ul><li>A Recovering PHP Developer </li></ul><ul><li>Contact Information: </li></ul><ul><li>Business E-mail: [email_address] </li></ul><ul><li>Personal E-mail: [email_address] </li></ul><ul><li>Personal Blog http://mashraqi.com </li></ul>
    • 3. What we’ll cover (aka the essentials) <ul><li>Why ROR? </li></ul><ul><li>MVC </li></ul><ul><li>Crash Course (Scaffolding etc) </li></ul><ul><li>URLs in ROR </li></ul><ul><li>Adoppt </li></ul><ul><li>AJAXifying Forms </li></ul><ul><li>Relationships / Validations </li></ul>
    • 4. The essentials continued <ul><li>Transactions </li></ul><ul><li>Blog Claims </li></ul><ul><li>Tagging </li></ul><ul><li>In place editing </li></ul><ul><li>Learn more </li></ul><ul><li>Q&amp;A </li></ul>
    • 5. Why would I use Ruby On Rails? <ul><li>RAD </li></ul><ul><li>DRY: “Do not Repeat Yourself” </li></ul><ul><li>Disciplined </li></ul><ul><li>Normalization </li></ul><ul><li>Relationships </li></ul><ul><li>Web Services </li></ul><ul><li>Everything is an Object </li></ul>
    • 6. MVC
    • 7. Crash Course [root@srv31 docs]# rails ror create create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create components create db create doc create lib create lib/tasks create log create public/images ... Creating a bare application on Rails [root@srv31 docs]# rails ror
    • 8. Do it with Scaffolding [root@srv31 ror]# ruby script/generate scaffold user exists app/controllers/ exists app/helpers/ create app/views/users exists test/functional/ dependency model exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/user.rb ruby script/generate scaffold user CRUD = ‘C’reate, ‘R’ead, ‘U’pdate, ‘D’elete
    • 9. Experience the magic http://localhost:3000/users http://localhost:3000/users/new
    • 10. Find functions <ul><li>find_by_[field_name] (field_value) </li></ul><ul><li>find_by_[field_name]_and_[field_name] </li></ul><ul><li>find_first </li></ul><ul><li>find_all_by </li></ul><ul><li>find() </li></ul><ul><li>find_by_sql(‘SELECT ….’) </li></ul>
    • 11. URLs in ROR &lt;%= link_to “Reply”, :controller=&gt;”posts”, :action=&gt;“reply”, :id=&gt;4 %&gt;
    • 12. What is Adoppt <ul><li>A replicatable social networking platform </li></ul><ul><li>Create and participate in communities </li></ul><ul><li>Blogs, Forums, Favorites and more </li></ul>
    • 13. &nbsp;
    • 14. &nbsp;
    • 15. Ajaxifying the login form <ul><li>Ajaxified version </li></ul>&lt;%= link_to “Login”, :controller=&gt;”member”, :action=&gt;”login” %&gt; Typical form in ROR &lt;%= link_to_remote “Login”, :url=&gt;{ :controller=&gt;”member”, :action=&gt;”login” }, :update =&gt; “loginform”, :loading =&gt; “Element.toggle($(‘loading’))”, :complete =&gt; “Element.toggle($(‘loading’))” %&gt; Same form ‘AJAXified’
    • 16. &nbsp;
    • 17. Relationships / Validations <ul><li>A community </li></ul><ul><ul><li>Has many members subscribed </li></ul></ul><ul><ul><li>Members can post favorite web sites </li></ul></ul><ul><ul><li>Belongs to a member or system </li></ul></ul>class Portal &lt; ActiveRecord::Base has_many :subscriptions has_many :favorites belongs_to :member validates_presence_of :portal_name validates_presence_of :portal_description validates_presence_of :portal_url validates_uniqueness_of :portal_url … end
    • 18. HABTM using Subscriptions class Member has_many :subscriptions end class Portal has_many :subscriptions end class Subscription belongs_to :member belongs_to :portal end
    • 19. Self referential relationships <ul><li>A member has many friends (member) </li></ul><ul><li>Self referential HABTM relationship </li></ul>class Member &lt; ActiveRecord::Base has_and_belongs_to_many :friends, : class_name =&gt; &amp;quot;Member&amp;quot;, : join_table =&gt; &amp;quot;friends_members&amp;quot;, : association_foreign_key =&gt; &amp;quot;friend_id&amp;quot;, : foreign_key =&gt; &amp;quot;member_id&amp;quot;, : after_add =&gt; :become_friend_with_friend, : after_remove =&gt; :end_friendship end
    • 20. Using relationships <ul><li>1. Which favorites were posted to a portal </li></ul>@portal = Portal.new @favorites = @portal.favorites 2. Which members are subscribed? @portal = Portal.new @members = @portal.subscriptions @member = Member.new @member_portals = @member.portals 3. Which portals a member is subscribed to? 4. Which members are friends of a member? @member = Member.new @friends = @member.friends
    • 21. Transactions (InnoDB) Member.transaction(@member, @friend) do @member.friends &lt;&lt; @friend unless @member.friends.include?(@friend) @friend.friends &lt;&lt; @member unless @friend.friends.include?(@member) end
    • 22. Blog Claims def claim_verify @wb= Weblog.find_by_url(@params[:url]) require &apos;open-uri‘ @found = open(@wb.url).read.include?(@wb.v_key) end
    • 23. Tagging <ul><li>acts_as_taggable gem (http://taggable.rubyforge.org/) </li></ul>
    • 24. Tagging class Article &lt; ActiveRecord::Base acts_as_taggable :join_class_name =&gt; &apos; TagArticle ‘ class TagArticle belongs_to :article, :class_name =&gt; &apos; Article &apos;, :foreign_key =&gt; &apos;article_id‘ @tagged = Article.tags_count(:limit =&gt; 10) Tagging an article @article = Article.new @article.tag “mysql conference ror” Tags for an article @tags = @article.tags() Tag Cloud (Tom Fakes)
    • 25. In place editing class BlogsController &lt; ApplicationController in_place_edit_for :weblog, :description &lt;%= in_place_editor_field :weblog, :description, :value=&gt;&apos;&apos; %&gt; In your views file In your model
    • 26. Recap <ul><li>ROR: Valuable to You </li></ul>
    • 27. Where to learn more <ul><li>Books </li></ul><ul><ul><li>Agile Web Development with Rails by Dave Thomas and David Heinemeier Hansson </li></ul></ul><ul><ul><li>Pro Rails by me </li></ul></ul><ul><ul><li>ROR Recipes by Chad Fowler </li></ul></ul><ul><li>Websites </li></ul><ul><ul><li>http://www.ruby-doc.org/ </li></ul></ul><ul><ul><li>http://www.rubygarden.org/ruby/ </li></ul></ul><ul><ul><li>http://www.ruby-lang.org/ </li></ul></ul><ul><ul><li>http://www.ruby-doc.org/stdlib/libdoc/rdoc/rdoc/index.html </li></ul></ul><ul><ul><li>http://script.aculo.us </li></ul></ul><ul><ul><li>http://rubyonrails.adoppt.com/blog/frank </li></ul></ul>
    • 28. Q&amp;A

    ×