Another new version of Rails. Delightful. And terrifying. What's changed this time? Fear Not!
We'll be reviewing the changes and additions to Rails 3.1, giving you a walk-through of what it all means (asset pipeline, what?), in the context of a brand new app, and an older app that will need to be upgraded.
11. What you HAVE to know
• Nothing
• Absolutely not required
• Just remove one line from Gemfile
• gem 'coffee-rails'
• And you don’t even have to do this
12. Thomas Fuchs on
CoffeeScript
• May 2011 - "I just like javascript too
much to have a use for that, but I
understand why other people might
like it"
• Aug 2011 - There, it happened.
Mistakenly typed CoffeeScript in a .js
file. So easy to pick up, and so natural.
13. CoffeeScript Resources
• Railscasts
• CoffeeScript Basics
• http://railscasts.com/episodes/267-coffeescript-basics
• Peepcode
• Meet CoffeeScript
• http://peepcode.com/products/coffeescript
• Books
• Pragmatic Programmers - CoffeeScript
• O’Reilly - The Little Book on CoffeeScript
15. What you HAVE to know
• Nothing
• Absolutely not required
• Just remove one line from your Gemfile
• gem 'sass-rails'
• And you don’t even have to do that
16. Is it SASS or SCSS?
• Sass is the older style HAML-like
indented syntax
• SCSS is the new main syntax, which is a
superset of CSS3
17. Why SASS?
• Variables
• Nesting
• DRY up your styles
• Mixins
• reusable chunks
• with arguments!
• Selector Inheritance
24. js manifest
• Powered by - Sprockets
• application.js
// FIXME: Tell people that this is a manifest
file, real code should go into discrete files
//
//= require jquery
//= require jquery_ujs
//= require_tree .
25. SASS - no sprockets
• probably don’t want to use manifests
• use @import, or your variables and
scopes will not work
26. Dev vs Production
• To precompile, or not to precompile
• Heroku
• Cedar stack
• counter-intuitive settings
30. enabling
• application.rb
# Enable IdentityMap for Active Record,
to disable set to false or remove the line
below.
config.active_record.identity_map = true
So, out with the old, and in with the new. Prototype was the default Javascript library in Rails since the very beginning. There have been rumblings for several (intermediate) versions, but they finally pulled the trigger and did it.\n
However, if you just HAVE to use Prototype, it is just a simple -j option away. The choice of Javascript libs is now tucked away into a couple of gems\n\n\n
gem 'jquery-rails' or gem 'prototype-rails' will show up in your Gemfile\nAnd prototype or jquery js will be included via your application javascript manifest file\n- But, I get ahead of myself\n\n
Almost 10x more popular than Prototype\n\nPopularity == ecosystem\n\nVersioning... rails dictates which jQuery version now, which is better\n
But it’s important to note that CoffeeScript, while defined as a dependency by default in Rails 3.1, is not a requirement. You can just stick with pure Javascript (and jQuery) and call it done.\n\nNow, I consider myself just a dabbler in CoffeeScript, so I won’t spend a lot of time on it.\n\n
Thomas Fuchs, author of the Scriptaculous framework, co-author of the JavaScript Performance Rocks! ebook had this to say about CoffeeScript\n
However, if you really want to learn it, and I suggest you do, there are some great resources out there. \n
Syntactically Awesome Stylesheets\n
\n
Guess which one is recommended? ;-)\n
\n
\n
It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines\n
So, the assets (images, javascripts, & stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
So, the assets (images, javascripts, & stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
So, the assets (images, javascripts, & stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
So, the assets (images, javascripts, & stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
\n
\n
generate something to run on heroku to demo diff\n
\n
Average load time\nNumber of resource requests\nCDN\n\n
Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion.\nRails 3.1 comes with the identity map turned off by default. There are issues...\n
\n
\n
\n
Didn’t used to be able to nest these\n\nWord of warning. You may, or may not run into problems on non-default databases. And I can practically guarantee the you will have problems if you used this in conjunction with a legacy database with composite primary keys.\n
change\n
Instead of up and down. This works for straight-forward migrations, but if you are doing something special, you will probably still want up & down.\n
HTTP Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it.\n