The first question that comes to mind is should we store the guest user account in the database if it’s just temporary? Our application is currently structured so that a user has many tasks and we use this association in the TasksController to ensure that only the current user’s tasks...
Find out exactly what Rails is doing under the hood when it renders a view template for a response. What object context handles the template? How does the lookup process work? That and more covered in this code walkthrough.
FnordMetric allows you to chart events in real time. This is great for keeping track of user activity in your Rails app as demonstrated in this episode.
Allow users to import records into the database by uploading a CSV or Excel document. Here I show how to use Roo to parse these files and present a solution for validations.
#395 Action Controller Walkthrough pro Dec 02, 2012 | 11 minutes | Controllers , Rack Do you ever wonder what goes on behind the scenes when a Rails controller handles a request? What do the "render" and "redirect_to" methods do exactly? This and more covered as we walk through the co...
#162 Tree-Based Navigation (revised) Dec 01, 2012 | 10 minutes | Active Record , Plugins , Views If your Rails app is content-heavy, consider organizing it in a tree menu structure. Here I show how to add top-level tabs, nested links in a side bar, and breadcrumbs to go up the hierarc...
#394 STI and Polymorphic Associations Nov 25, 2012 | 14 minutes | Refactoring , Active Record Single Table Inheritance (STI) can help organize branching logic into separate classes, but a polymorphic association may be a better fit if there are unique database columns. Subscribe to Wa...
Unfortunately there is no easy solution to this problem. What we’ll do is keep the validation and redirect the user to a form where they can fix any problems if the validation fails when we try to save the new user. We’ll change the code in create so that if the validation fails when ...
Even though this has worked it’s annoying to have to remember to make this change every time we change a template and this is where the Cache Digests gem comes in useful. This functionality will be available by default in Rails 4 but has been extracted out into a gem so that we can us...
Instead of presenting a sign up form to the user, consider creating a temporary guest record so the user can try out the application without filling in their information up front. They can then become a permanent member afterwards.
#392 A Tour of State Machines Nov 17, 2012 | 12 minutes | Plugins , Active Record , Testing Here I show how three popular state machine gems can be used to clean up a list of boolean/datetime fields. I also show a custom solution which keeps track of the history of events. Subscribe t...
#103 Site-Wide Announcements (revised) Nov 12, 2012 | 11 minutes | Active Record , Ajax , Testing Here I show how to add an announcement message at the top of every page in the application and allow the user to permanently hide it. This is all done test-first and even includes testing...
RubyGems can make it easy to add a feature to a Rails application, but it can also cause headaches down the road. Here I give some tips on researching gems to decide which one to choose, or when to do it from scratch.
Ransack allows you to easily build complex search forms. It also helps in adding sortable links and building a dynamic advanced search page.
PhantomJS allows us to test JavaScript without going through a browser window. Here I show how to do this using Capybara and Poltergeist. I also give some tips on handling database transactions and skipping javascript tests.
Turbolinks can make your Rails app feel faster by using JavaScript to replace the page content when clicking a link. It will be default in new Rails 4.0 applications, but here I show how to use it in Rails 3 and mention some of the gotchas.
This past week's topics are on Turbolinks and PhantomJS. I ran into some challenges with these topics which has delayed them into this week. The good news is I'm done recording the Turbolinks episode and will be releasing it tomorrow (Monday). I expect to have the PhantomJS episode up...
Some things have changed since OmniAuth version 1.0 was released. Each provider is now a separate gem that should be included in the Gemfile, and the "user_info" hash is now simply "info". The changes have been made below.
This libarary is written using ARel from the ground-up. This leaves the code much cleaner than many implementations. ranked-model is also optimized to write to the database as little as possible: ranks are stored as a number between -8388607 and 8388607 (the MEDIUMINT range in MySQL)....
#106 Time Zones (revised) Oct 28, 2012 | 7 minutes | Active Support Active Support makes it easy to work with time zones. Learn how to add a Time Zone select field to a user form and watch out for the gotchas. Subscribe to Watch Episode Tweet Show Notes 2 Comments Similar Episodes < P...
Here I go back to the basics and show how to turn a traditional Rails app into one that interacts through Ajax by adding "remote" options, JavaScript templates and a dabble of jQuery.
Category Load (0.2ms) SELECT "categories".* FROM "categories" ORDER BY name Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."category_id" = 3 Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."category_id" = 1 Product Load (0.2ms) SELE...
#389 Multitenancy with PostgreSQL Oct 27, 2012 | 11 minutes | Active Record , Authorization PostgreSQL Schemas can help create a multi-tenant app by keeping data separate at the database layer. Integrating with migrations can be tricky though, so watch this episode for the full detail...
There are many approaches to locking down an API. Here I start off with HTTP Basic authentication then move on to generating a unique token which can be passed through a URL parameter or HTTP header.
This migration creates two tables: tags and taggings . We don’t have to create models for these as they’re included with the gem so we can get started with adding tagging to our application. We want an extra field on the page for editing an article where we can add tags for that artic...
#388 Multitenancy with Scopes Oct 20, 2012 | 12 minutes | Active Record , Authorization A multi-tenant application can be difficult to implement because the data for each tenant must be completely separate. Here I show how to do this using subdomains and default scopes in Active Recor...
The cache_digests gem (also included in Rails 4) will automatically add a digest to the fragment cache key based on the template. If a template changes the cache will auto-expire. But watch out for the gotchas!
Keeping passwords and secret tokens in source control is a security risk. Here I show how to move these settings out into a YAML configuration file which can be loaded in as a hash or environment variables.
Here you will learn how to upload multiple files over ajax using jQuery File Upload. I start with the basic functionality and customize it to fit the user interface.