Devchat.tv Episode Roundup

Devchat.tv Episode Roundup

Download on the App Store

All Devchat.tv Episode Roundup episodes

  • Model Generator
    Here's an introduction to creating a Rails connector gem for an ORM with a model generator.
    Download 352.3 MB
    Download (iPod & iPhone) 84.7 MB
    Take the 2011 Readers Survey
    0 min
  • 025 RC Eager Loading
    Eager loading is a terrific way of speeding up your response times. Let's consider a piece of code that pulls a list of associated objects from the database. For example, a view that displays the posts written by a given user:
    <% @user.posts.each do |post| %>
    <%= render post %>
    <% end %>
    (I know that partial has a collection option for things like this. I feel that this code sample is more expressive for our discussion.)
    In this case, assuming that @user was loaded by calling User.find(1), your Rails application is going to go to the database for each post. So, if the user has 40 posts in the system, the Rails application will make 40 trips to the database to get the posts.
    The problem is that if there is any latency on the database connection, it adds up.
    The fix for this is the use of the 'includes' method when querying for the user. User#includes tells the query to pull in whatever associated records you specify in its arguments. So, if we found @user by calling User.includes([:posts]).find(1), it would pull the user's record and all of the user's posts records and cache all of the user's posts on the user's object.
    The argument for 'includes' is an array. The objects in the array can be symbols or hashes. Symbols represent that associations the Model has. Hashes are used for including nested associations. For example, if we wanted to pull all of the comments on the user's posts. Here's another example:
    # In the controller
    @user = User.includes([:address, :phone_number, {:posts => [:comments]}]).find(1)
    # In the view 
    <% @user.posts.each do |post| %>
    <%= render post %>
    <% post.comments.each do |comment| %>
    <%= render comment %>
    <% end %> 
    <% end %>
    8 min
  • Rails 3.1 Asset Pipeline
    Assets in Rails before version 3.1 were kept in the /public folder. In Rails 3.1 they've been moved to /app/assets and function in a slightly different way. Here are some of the highlights:
    Javascript assets written in Coffeescript will now be compiled to Javascript.
    CSS assets written in SASS or SCSS will now be compiled to CSS
    Other templating languages like ERB can be used in assets
    JQuery is now the default Javascript framework in Rails 3.1
    You can combine Javascript files with the new directives
    Pre-compiled assets
    When compiling from SASS, SCSS, CoffeeScript, or ERB, you simply add the appropriate extension to your .js or .css file. (.sass, .scss, .coffee, or .erb respectively)
    To combine several Javascript files into one file, (for example application.js) just do something like this.
    //= require jquery
    //= require jquery_ujs
    //= require_tree .
    //= require_directory tooltips
     
    For several CSS files, it's the same commands, just *= instead of //= and wrapped in /* ... */. Here's a quick example:
    /*
    *= require reset
    *= require base
    *= require_tree .
    *= require_directory tooltips
    */
     
    require pulls in a file. require_tree gets everything in the specified path. require_directory pulls in all the files in a given directory (no nesting).
    You can precompile your assets by running bundle exec rake assets:precompile (For example, if your server doesn't have a Javascript runtime on it capable of compiling Coffeescript.)
    Here are some resources for CoffeeScript:
    The Coffeescript Website
    CoffeeScript Basics (video)
    CoffeeScript: The Cool Parts (video)
    10 min
  • Introduction to Sandra: The Cassandra ORM
    When I started playing with Cassandra, I wound up writing part of an ORM to get what I needed from it.
    I want to build actual projects with Rails, Ruby, or other technologies for my videos rather than just narrowly demonstrate a piece of technology. So, I'm bringing you up to speed with Sandra so that as I continue with the Twitter Clone, you'll know what I'm using and why I'm adding things to it.
    Sandra is available on Github at https://github.com/charlesmaxwood/sandra
    Download 531.0 MB
    Download (iPod & iPhone) 111.8 MB
    Take the 2011 Readers Survey
    0 min
  • Introduction to Sandra: The Cassandra ORM
    When I started playing with Cassandra, I wound up writing part of an ORM to get what I needed from it.
    I want to build actual projects with Rails, Ruby, or other technologies for my videos rather than just narrowly demonstrate a piece of technology. So, I'm bringing you up to speed with Sandra so that as I continue with the Twitter Clone, you'll know what I'm using and why I'm adding things to it.
    Sandra is available on Github at https://github.com/charlesmaxwood/sandra
    Download 531.0 MB
    Download (iPod & iPhone) 111.8 MB
    Take the 2011 Readers Survey
    0 min