Get Going With RVM and Rails 3


Published on

Get started using RVM to manage multiple Ruby versions and get started with Rails 3.

Published in: 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

No notes for slide

Get Going With RVM and Rails 3

  1. 1. Get started with Rails 3 by Karmen Blake Rails 3: Overview RVM: Ruby Version Manager Basic Rails 3 App
  2. 2. Rails 3: Overview
  3. 3. Rails 3: Overview Merb Fast Lightweight Powerful = featureful, flexible, and extensible Rails Popular Easy to get started Opinionated Large ecosystem: books, blogs, screencasts, community
  4. 4. Rails 3: Overview
  5. 5. Ruby Version Manager (RVM) Why? For me, I've been attached to Ruby 1.8.6 for a long time. Mostly because it is stable and legacy projects I work on rely on it. Lots of gems installed that just work. Rails 3 requires 1.8.7 and above! Doh!!!
  6. 6. Ruby Version Manager (RVM) Command line tool which allows us to easily install, manage and work with multiple ruby environments (and associated gems).
  7. 7. Ruby Version Manager (RVM)
  8. 8. Ruby Version Manager (RVM) Installation: > mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/ && git clone --depth 1 git:// && cd rvm && ./install That is a long command, eh. You might want to go here and read for yourself: http://rvm. Follow instructions after that which involves adding a line to your bash profile.
  9. 9. Installing Rails Using RVM > rvm install 1.9.1 (or 1.8.7 or 1.9.2) > rvm 1.9.1 --default (uses 1.9.1 on newly opened terminal windows) > curl -L -o rails3.gems > rvm gemset import rails3.gems > rails -v (should show Rails 3 beta) You may have to install sqlite/mysql and associated gems. For example, > gem install sqlite3-ruby
  10. 10. Ruby Version Manager (RVM) A few more things: To use system ruby installed by default: > rvm system --default See installed rubies: > rvm list Named Gem Sets RVM not only isolates different ruby installations it also lets you isolate different gem sets. Thus you can mix and match rubies and gem sets. Amazing!! More here: http://rvm.
  11. 11. Introduction to Rails 3 Generate a Rails 3 app > rails generate app_name > rails g app_name script/rails is the only thing in there! Generate scaffold > rails g scaffold Post title:string body:text > rake db:migrate Start server > rails server > rails s
  12. 12. Introduction to Rails 3 Console > rails console > rails c Database Console > rails dbconsole > rails db
  13. 13. Introduction to Rails 3 ActiveRecord Validation Rails 2 - separate validations validates_presence_of :title validates_uniqueness_of :title validates_length_of :title, :maximum => 35 Rails 3 - puts validations together for a field validates :title, :presence => true, :uniqueness => true, :length => {:maximum => 35}
  14. 14. Introduction to Rails 3 ActiveRecord Query Interface New API where(:conditions) having(:conditions) select group order limit includes(:include) and more...
  15. 15. Introduction to Rails 3 ActiveRecord Query Interface Why New API? Chainability!!!! No not gold chains. :) Post.where(:title => "test") Post.where(:title => "test").order("created_at DESC") Post.order("created_at").limit(10) Post.where("created_at <= ?",
  16. 16. Introduction to Rails 3 ActiveRecord Query Interface Lazy Loading posts = Post.all Returns a ActiveRelation object containing information about query. As soon as you access ActiveRelation object, for example in view, then call gets executed to db. Nice for fragment caching, etc. <% posts.each do |post| %> <li><%= post.title %></li> <% end %>
  17. 17. Introduction to Rails 3 More Rails 3 Goodies: Router Mailer Unobtrusive Javascript ... Will have to wait for another presentation. :)
  18. 18. Introduction to Rails 3 All you want to know and more about Rails 3 3-a-link-list/
  19. 19. References code-3219240 rails-3 pik rvm tool on windows, I've never used though
  20. 20. Karmen Blake