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

Ruby On Rails


Published on

Ruby on rails, components, ActiveRecord, Routing

Ruby on rails, components, ActiveRecord, Routing

Published in: Software, Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Ruby on Rails Mehmet Beydogan 2014
  • 2. Ruby on Rails Mehmet Beydogan 2014
  • 3. Why Ruby? “Ruby is natural more than simple”
  • 4. Everything is an object 5.times do puts “Hello World” end Hello World Hello World Hello World Hello World Hello World 5.class => Fixnum=> Fixnum nil.class => NilClass
  • 5. Ruby Blocks patients.each do |patient| if patient.ill? physician.examine patient else patient.jump_for_joy! end end You can group a set of instructions together
  • 6. Open Classes class String def write_size self.size end end size_writer = "Tell me my size!" puts size_writer.write_size In Ruby, classes are never closed, you can always add methods to an existing class.
  • 7. Method Missing class Dummy def method_missing(m, *args, &block) puts "There's no method #{m}" end end method_missing is in part a safety net: It gives you a way to intercept unanswerable messages and handle them gracefully
  • 8. Method Missing User.find_by_name User.find_by_email You can use regular expressions to more dynamic classes
  • 9. Ruby on Rails
  • 10. Rails -Convention Over Confuguration -DRY – Dont Repeat Yourself -MVC Princibles
  • 11. Convention Over Confuguration Model: User Table: users Controller: users_controller
  • 12. MVC
  • 13. REST -simplifies component implementation -reduces the complexity of connector semantics,
  • 14. Rails Components -Active Record -Database Migrations -Active Record Validations -Active Record Callbacks -Active Record Assocations Model Layer -Action View -Layouts & Partials -Rendering View Layer -Controller Overview -Routing Controller Layer
  • 15. Rails Components -i18n -Action Mailer -Asset Pipeline -Generators More Components
  • 16. Model Layer
  • 17. Active Record -Represent models and their data -Represent associations between these models -Represent inheritance hierarchies through related models -Validate models before they get persisted to the database -Perform database operations in an object-oriented fashion.
  • 18. Creating Active Record Models
  • 19. Read
  • 20. Update
  • 21. Delete
  • 22. Active Record Migrations app/db/migrations/create_publications.rb
  • 23. Active Record Migrations Supported Methods add_column add_index add_reference add_timestamps create_table create_join_table drop_table drop_join_table remove_timestamps rename_column rename_index remove_reference rename_table
  • 24. Running Migrations
  • 25. Active Record Validations Validations are used to ensure that only valid data is saved into your database.
  • 26. format
  • 27. length
  • 28. numericality
  • 29. presence
  • 30. uniqueness
  • 31. Validation Errors
  • 32. Active Record Callbacks -Active Record provides hooks into this object life cycle so that you can control your application and its data. -Callbacks allow you to trigger logic before or after an alteration of an object's state.
  • 33. Callback Registration
  • 34. When does it get triggered? -Creating an Object before_validation after_validation before_save around_save before_create around_create after_create after_save -Updating an Object before_validation after_validation before_save around_save before_update around_update after_update after_save -Destroying an Object before_destroy around_destroy after_destroy
  • 35. Active Record Associations They make common operations simpler and easier in your code. -Get a user's all posts -Get the author of a post
  • 36. Why Associations? Consider we have Order and Customer models
  • 37. Why Associations? Creating an order
  • 38. Why Associations? Deleting all orders of a customer while deleting a customer
  • 39. IT'S PAINFUL!
  • 40. Use Associations Creating an order Deleting a customer with it's orders
  • 41. belongs_to
  • 42. has_one
  • 43. has_many
  • 44. has_and_belongs_to_many
  • 45. has_many through
  • 46. Polymorphic
  • 47. View Layer -Action View -Layouts & Partials -Rendering
  • 48. Action View -Action View is responsible for compiling the response. -Action View templates are written using embedded Ruby in tags mingled with HTML. -All view files must be in app/views folder
  • 49. app/views/posts/index.html.erb app/views/posts/new.html.erb app/views/posts/edit.html.erb app/views/posts/show.html.erb
  • 50. Templates ERB: Embedded RuBy list_people.html.erb
  • 51. Partials To simplify templates
  • 52. Controller Layer -Controller Overview -Routing
  • 53. Controller Layer -Controller is responsible for making sense of the request and producing the appropriate output -Rails favors pluralization of the last word in the controller's name ClientsController SiteAdminsController PostsController
  • 54. Routing -The Rails router recognizes URLs and dispatches them to a controller's action. -Generate paths and URLs, avoiding the need to hardcode strings in your views. routes.rb Request index.html.erb
  • 55. Where to start? - -
  • 56. Questions?