14
Athens Ruby Meetup #4 Rails 3: Derailing Rails Panagiotis Papadopoulos @panosjee http://6pna.com

Derailing rails

Embed Size (px)

DESCRIPTION

My presenation at Athens Ruby Meetup #4

Citation preview

Page 1: Derailing rails

Athens Ruby Meetup #4

Rails 3:Derailing

Rails

Panagiotis Papadopoulos@panosjeehttp://6pna.com

Page 2: Derailing rails

Merb and Rails merge announced on December 23 2008The hell freezedHigh ExpectationsTwo and a half years later the merge is completeA lot of new committersSignificant efforts by the Merb creator Yehuda KatzLots of rewritesA new beastNew tricks to learnMore power to developersLess opinionated thus derailed but still using strong conventionsLess monkey patching (oh yes)

The story after Rails 3

Page 3: Derailing rails

Many people accused Rails of being spaghetti code

Page 4: Derailing rails

Not any more...

Django infuelnces...

Page 5: Derailing rails

Less monkey patching.The code is well organized and modular.You can reuse the components you want, add yours and create the Rails you want, ala carte

* you can always monkey patch, do not worry!

Page 6: Derailing rails

Rails 3 is a top Rack citizen. You can mount any Rack or even Sinatra in your app.

It is as simple as that:

Store::Application.routes.draw do |map| root :to => proc { |env| [200, {}, ["Welcome"]] } end

Or if you want a custom controller:In your routes.rb

match "/processes" => ProcessesApp

In lib/process_app.rb

class ProcessesApp < ActionController::Metal include ActionController::Rendering append_view_path "#{Rails.root}/app/views" def index @processes = `ps -axcr -o "pid,pcpu, pmem, time, comm"` render end end

Pure Rack Goodness

Page 7: Derailing rails

New Responders, less verbosedef new @product = Product.new respond_with @product end

Redirect shortcuts redirect_to @product, :notice => "Successfully created

Permanent CookiesCustom responedersNo more Metal, you can create your own controllers

Controllers in Rails 3

Page 8: Derailing rails

No more gem.config in environment.rbAnyway all this code is moved to application.rbBut your gem dependencies now live in GemfileBundler is the new way to solve the dependency hell problem.Bundler locks all used gems so when you clone the project you get the same exactly gems and dependencies# Edit this Gemfile to bundle your application's dependencies. source 'http://gemcutter.org' gem "rails", "3.0.0.beta" # ActiveRecord requires a database adapter. By default, # Rails has selected sqlite3. gem "sqlite3-ruby", :require => "sqlite3"

Gem dependecies. Bundler.

Page 9: Derailing rails

Forget script, say hello to rails

New Generators and Commands

Generators help you create *YOUR* convetions

Page 10: Derailing rails

The new ActionMailer is descentant of ActionController so you no longer have to mixin your models and mailers.

class UserMailer < ActionMailer::Base default :from => "[email protected]" def registration_confirmation(user) mail(:to => user.email, :subject => "Registered") end end

A new ActionMailer! At last!

Page 11: Derailing rails

Everything is escaped by default. Use <%=raw %> if you want markup in your views.First of all Rails 3 is not tight to Prototype. It is still the default but you can use easily any major Javascript library.All helpers produce UJS codeIn your views: <%= link_to "Destroy", @product, :confirm => "Are you sure?", :method => :delete %> Produces the following html code: <a href="/products/8" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a>

Unobtrusive JS using HTML5, XSS Security

Page 12: Derailing rails

ActiveRecord inherits from ActiveModelYou can use ActiveModel to build your own ORM compatible with RailsQuery language is now AReLChain everything!More details by Savvas

ActiveRecord

Page 13: Derailing rails

An awesome way to extend Rails apps! Build plugins in no time!

Source: http://www.igvita.com/2010/08/04/rails-3-internals-railtie-creating-plugins/

Railties

Page 14: Derailing rails

Rails 3 bring more options to developers and a better API to build upon.

You still have the Golden Path

or the Rails defaults but you

face less restrictions on

how to build stuff

Huge performance gains

You better start off with Ruby 1.9 using RVM so that you migrate to the new Ruby stack

Be careful with your gem and plugins selections, things are a bit... edgy

Tested against other major VMs such as Ruby 1.8, 1.9,

JRuby, Rubinious

Thank You!@panosjee