get going with rvm and rails 3
DESCRIPTION
Get started using RVM to manage multiple Ruby versions and get started with Rails 3.TRANSCRIPT
Get started with Rails 3
Rails 3: Overview
RVM: Ruby Version Manager
Basic Rails 3 App
by Karmen Blake
Rails 3: Overview
Rails 3: Overview
MerbFastLightweightPowerful = featureful, flexible, and extensible
RailsPopularEasy to get startedOpinionatedLarge ecosystem: books, blogs, screencasts, community
Rails 3: Overview
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!!!
Ruby Version Manager (RVM)
Command line tool which allows us to easily install, manage and work with multiple ruby environments (and associated gems).
Ruby Version Manager (RVM)
Ruby Version Manager (RVM)
Installation:
> mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/ && git clone --depth 1 git://github.com/wayneeseguin/rvm.git && cd rvm && ./install
That is a long command, eh.
You might want to go here and read for yourself: http://rvm.beginrescueend.com/rvm/install/
Follow instructions after that which involves adding a line to your bash profile.
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 http://rvm.beginrescueend.com/gemsets/rails3.gems -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
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 SetsRVM 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.beginrescueend.com/gemsets/basics/
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
Introduction to Rails 3
Console> rails console> rails c
Database Console> rails dbconsole> rails db
Introduction to Rails 3
ActiveRecord Validation
Rails 2 - separate validations validates_presence_of :titlevalidates_uniqueness_of :titlevalidates_length_of :title, :maximum => 35
Rails 3 - puts validations together for a fieldvalidates :title, :presence => true, :uniqueness => true, :length => {:maximum => 35}
Introduction to Rails 3
ActiveRecord Query Interface
New APIwhere(:conditions)having(:conditions)selectgrouporderlimitincludes(:include)and more...
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 <= ?", Time.now).includes(:comments)
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 %>
Introduction to Rails 3
More Rails 3 Goodies:
Router
Mailer
Unobtrusive Javascript
...
Will have to wait for another presentation. :)
Introduction to Rails 3
All you want to know and more about Rails 3
http://mediumexposure.com/rails-3-reading-material/ http://www.rubyinside.com/rails-3-0-beta-links-2966.html http://railslove.com/weblog/2010/02/02/on-the-way-to-rails-3-a-link-list/http://railsnotes.com/rails-3/
References
http://www.slideshare.net/GreggPollack/rails-3-beautiful-code-3219240http://guides.rails.info/getting_started.htmlhttp://railscasts.com/episodes/202-active-record-queries-in-rails-3http://m.onkey.org/2010/1/22/active-record-query-interfacehttp://rvm.beginrescueend.com/pik
rvm tool on windows, I've never used thoughhttp://github.com/vertiginous/pik
Karmen Blake
http://www.dudeblake.comhttp://blog.dudeblake.comhttp://twitter.com/kblakehttp://github.com/kblake