Rails 3.1  Lori Olson Confoo 2012 Montreal, QC
Another new version of Rails. Delightful. And terrifying.  Whats changed this time?
Summary• jQuery• CoffeeScript• SASS• Asset Pipeline• Miscellaneous cool stuff
But...• What about Rails 3.2? • only released a few weeks ago • not nearly as many scary changes
jQuery
What you HAVE to know• How to go back to Prototype (not  recommended • rails new my_app -j prototype
Differences• Gemfile gem ‘jquery-rails’• application.js //= require jquery //= require jquery_ujs
But... Why jQuery?
CoffeeScript
What you HAVE to know• Nothing• Absolutely not required• Just remove one line from Gemfile • gem coffee-rails • And you don...
Thomas Fuchs on      CoffeeScript• May 2011 - "I just like javascript too  much to have a use for that, but I  understand ...
CoffeeScript Resources• Railscasts  • CoffeeScript Basics  •   http://railscasts.com/episodes/267-coffeescript-basics• Pee...
SASS
What you HAVE to know• Nothing• Absolutely not required• Just remove one line from your Gemfile • gem sass-rails • And you ...
Is it SASS or SCSS?• Sass is the older style HAML-like  indented syntax• SCSS is the new main syntax, which is a  superset...
Why SASS?• Variables• Nesting • DRY up your styles• Mixins • reusable chunks • with arguments!• Selector Inheritance
Alternatives to SASS• Less• HSS• Other, technology specific • XCSS (PHP) • CleverCss (Python) • CSS Crush (PHP)
Asset Pipeline
assets dir
assets dir
assets dir
assets dir
js manifest• Powered by - Sprockets• application.js  // FIXME: Tell people that this is a manifest  file, real code should ...
SASS - no sprockets• probably don’t want to use manifests• use @import, or your variables and  scopes will not work
Dev vs Production• To precompile, or not to precompile• Heroku • Cedar stack • counter-intuitive settings
Compression• Uglifier (for javascript)• SCSS (for css)
But, Why?
Identity Map
enabling• application.rb  # Enable IdentityMap for Active Record,  to disable set to false or remove the line  below.  con...
problems• associations• STI• tests
nestedhas_many :through
class Project < ActiveRecord::Base has_many :tasks has_many :assignments, :through => :tasks has_many :users, :through => ...
Migrations
class CreateProjects < ActiveRecord::Migration def change  create_table :projects do |t|   t.string :name   t.timestamps  ...
HTTP Streaming
requirements• Ruby 1.9.2 (min)• Web server support • nginx • unicorn
Examples
New App
Upgrade
Bundler• Did you know... you can use bundler all  the way down to Rails 2.1 apps?
Add Bundler• http://youtu.be/7UzGdqaDnp8
• Upgrade the Gemfile• Config file changes• Move the assets
Configs• boot.rb• config.rb• development.rb• production.rb
Assets• Move asset folders• Fix image references• Manifests• stylesheet and javascript tag references
Upgrade Demo• Upgrading a Rails 2.1 app to Rails 3.1 in  1…
Rails 3.1
Upcoming SlideShare
Loading in...5
×

Rails 3.1

1,215

Published on

Another new version of Rails. Delightful. And terrifying. What&#039;s changed this time? Fear Not!

We&#039;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.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,215
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • 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 &apos;jquery-rails&apos; or gem &apos;prototype-rails&apos; 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
  • Infographic\nfile:///Volumes/loriolson/Confoo/Javascript%20Frameworks%20and%20jQuery%20(Infographic)%20%7C%20Web%20Resources%20%7C%20WebAppers.webarchive\n
  • \n
  • But it&amp;#x2019;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&amp;#x2019;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, &amp; 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, &amp; 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, &amp; 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, &amp; 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&amp;#x2019;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 &amp; 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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Rails 3.1

    1. 1. Rails 3.1 Lori Olson Confoo 2012 Montreal, QC
    2. 2. Another new version of Rails. Delightful. And terrifying. Whats changed this time?
    3. 3. Summary• jQuery• CoffeeScript• SASS• Asset Pipeline• Miscellaneous cool stuff
    4. 4. But...• What about Rails 3.2? • only released a few weeks ago • not nearly as many scary changes
    5. 5. jQuery
    6. 6. What you HAVE to know• How to go back to Prototype (not recommended • rails new my_app -j prototype
    7. 7. Differences• Gemfile gem ‘jquery-rails’• application.js //= require jquery //= require jquery_ujs
    8. 8. But... Why jQuery?
    9. 9. CoffeeScript
    10. 10. 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
    11. 11. 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.
    12. 12. 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
    13. 13. SASS
    14. 14. 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
    15. 15. 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
    16. 16. Why SASS?• Variables• Nesting • DRY up your styles• Mixins • reusable chunks • with arguments!• Selector Inheritance
    17. 17. Alternatives to SASS• Less• HSS• Other, technology specific • XCSS (PHP) • CleverCss (Python) • CSS Crush (PHP)
    18. 18. Asset Pipeline
    19. 19. assets dir
    20. 20. assets dir
    21. 21. assets dir
    22. 22. assets dir
    23. 23. 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 .
    24. 24. SASS - no sprockets• probably don’t want to use manifests• use @import, or your variables and scopes will not work
    25. 25. Dev vs Production• To precompile, or not to precompile• Heroku • Cedar stack • counter-intuitive settings
    26. 26. Compression• Uglifier (for javascript)• SCSS (for css)
    27. 27. But, Why?
    28. 28. Identity Map
    29. 29. enabling• application.rb # Enable IdentityMap for Active Record, to disable set to false or remove the line below. config.active_record.identity_map = true
    30. 30. problems• associations• STI• tests
    31. 31. nestedhas_many :through
    32. 32. class Project < ActiveRecord::Base has_many :tasks has_many :assignments, :through => :tasks has_many :users, :through => :assignmentsend
    33. 33. Migrations
    34. 34. class CreateProjects < ActiveRecord::Migration def change create_table :projects do |t| t.string :name t.timestamps end endend
    35. 35. HTTP Streaming
    36. 36. requirements• Ruby 1.9.2 (min)• Web server support • nginx • unicorn
    37. 37. Examples
    38. 38. New App
    39. 39. Upgrade
    40. 40. Bundler• Did you know... you can use bundler all the way down to Rails 2.1 apps?
    41. 41. Add Bundler• http://youtu.be/7UzGdqaDnp8
    42. 42. • Upgrade the Gemfile• Config file changes• Move the assets
    43. 43. Configs• boot.rb• config.rb• development.rb• production.rb
    44. 44. Assets• Move asset folders• Fix image references• Manifests• stylesheet and javascript tag references
    45. 45. Upgrade Demo• Upgrading a Rails 2.1 app to Rails 3.1 in 1…
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×