Bret and I have been working on a pretty extensive update to Tempo, our time-tracking service, that required revisiting how we detect mobile devices and provide mobile views where appropriate and/or available.
To that end I took a look at mobile-fu, a Rails plugin by Intridea’s Brendan Lim, which automatically detects mobile devices and sets the request format to :mobile, a commonly used mime-type alias for those looking to provide mobile views. You can check out his blog post on the plugin for full details, but the basics of it are that by setting the request.format to :mobile, you can automatically serve up custom views (e.g. new.mobile.erb), perhaps in a custom layout, etc. The plugin also will automatically attempt to include mobile_blackberry.css if you are already including a mobile.css file and the user is working off of a blackberry.
That’s almost perfect! However, we don’t support mobile views all over Tempo, it’s a bit impractical at the moment, especially given how well smart phone browsers like Mobile Safari handle normal web pages. Instead, we provide a basic mobile interface for logging in and logging time. We do want that to render automatically, but we also want the user to be able to exit out of the mobile view easily, and have that stick with his session.
So I forked mobile-fu on github, got things working the way I needed ‘em, and posted the changes back up. It now provides automatic detection of mobile devices with more dynamism (you call before_filter yourself, where you want it, with the options you need), and you can use the ’bypass’ parameter on any request to toggle the session-based bypass of the mobile view that allows the user to avoid it if he doesn’t actually want it.
Pushed-to-github-and-blogged-too-soon Update:
The use of a ‘bypass’ in the way I’ve done it here becomes somewhat less useful when you want a user to be able to easily enable the mobile view when their mobile device is not detected (e.g. a ‘Switch to Mobile View’ link on the login screen). So, I’ve hacked away at this a bit more and I’ve got another implementation to commit and push to this fork when I get a few minutes.
The main problems I ran into in all of this were not really the problem of mobile-fu, but more of an issue with how Rails handles the use of request.format, the aliased mime-type (i.e. :mobile => 'text/html'), and forwarding from one domain to another. Will try to detail how we’re handling it all shortly.
I was intrigued by Steven Frank’s recent blog post describing how Panic software approaches communicating with customers about feature announcements and product updates. Like Panic, we tend to say little, work a lot behind the scenes, but it sounds like once in a while it’s a good idea to get out in front with a blog post to let your customers know what we’ve been working on and what’s coming.
Our primary development focus with Strip at the current time is a replication library that will be the core of our sync process, and it will likely become an open source project. Many folks have been emailing us to say that they love Strip on the iPhone, but they need desktop sync, and some of them miss the old beaming functionality of STRIP on their Palm devices. The replication engine is almost complete, and is the key to enabling these additional pieces of the Strip platform.
Meanwhile, we’ve got a maintenance update brewing for Strip on the iPhone. We expect the following issues to make it in to the next update, time permitting:
Bug: Loss of typed data on lock out while creating a note. (Fixed)
Convert existing database cipher mode to improve compatibility with standard SQLCipher configuratione. (In-progress)
Rename Lite → Strip migration button for clarity. (Fixed)
Fun: Facebook Connect hook for spreading the word. (Complete)
Allow copy & duplication of entries so that you can create “template” entries or share common fields. (In-progress)
Protect database re-key from application interruptions. (In-progress)
Enable FTS3 (full-text) searching, search on type.
Bug: Attempts to re-order the Add Field row cause a crash.
UPDATE: have just released a free Palm Strip Export utility for Windows that can dump your Palm OS 2.0 databases to a CSV text file. Check it out here.
So here I am, minding my own business on Labor Day, working on the upcoming teams branch of Tempo. Basically, it introduces a new account model that’s distinct from users and projects, ideally facilitating the setup of teams for small organizations. Accordingly, an account has an owner, and every user belongs to an account. In addition, users can be managers for the whole account (new!), or users can be marked as a manager for a particular project assignment.
This all sounds great on paper, but in the Projects controller there arise a number of concerns:
The account owner or one of the managers should see all the account’s projects on the projects index, and also the /archive resource collection
All other users should only see accounts they are assigned to as managers
index should only show active projects and archive should only show inactive projects
index and archive both support an id parameter for the XML api, enabling the lookup of an aribitrary collection of managed projects
As you can imagine, this could lead to a lot of spaghetti in a controller method, that you’d want to hide away in a model. Typically, you’d want your User model to set up the various project collections as association (has_many) resources so you can provide find options as needed (such as :conditions => { :is_active => true }). That keeps your redundancy down, but your controller (or a model method) would have to conditionally decide which resource to provide. There was the possibility of adding a method to the user model that handled the conditional logic and passed back the right result set, but it would have been a royal pain to correctly pass through find options, especially given all the various circumstances above..
To make things further complicated, we need to also use these methods for the reporting interface and to make sure users only see the time entries they are supposed to see. That means keeping nonsense and code repetition to a minimum is critical.
ActsAsUnion is included in our ActsAsNetwork plugin, and it allows us to UNION together multiple associations and operate across them as we would any other association, by supporting the various find_* options we are used to with has_many.
On a tangential note, safe_find_from_ids is a quick and dirty monkey-patch we throw in an initializer so we can look up a set of ids that returns an empty set instead of raising an exception when no ids are found:
class ActiveRecord::Base def self.safe_find_from_ids(*args) ids = args.kind_of?(Array) ? args.flatten : [args] ids.empty? ? [] : self.find(:all, :conditions => ["#{self.table_name}.id IN (#{ids.collect{|p| '?'}.join(',')})", ids].flatten) end end
It’s not ideal, but it gets the job done. There may be a better way of doing it in recent versions of Rails, need to look into that.
Recently we hired Aaron Aiken’s Trim Trab Creative to put together some videos demonstrating how Tempo works, and the videos are coming out great (check out the main tour vid here). He has a real knack for putting together interesting demos and communicating the concepts at work in a piece of software.
We put a lot of thought and work in Tempo’s interfaces, but sometimes it gets tricky to explain some of the concepts to new users, especially some of the advanced controls that can save you a lot of time. Introducing people to the benefits of using our simple command line for time tracking is one of those tricky things. Aaron hit it out of the park:
Zetetic LLC is a small company specializing in applied data security. As the developers behind the SQLCipher encrypted database library and Codebook Password Manager, hundreds of organizations and millions of users trust Zetetic’s software and frameworks.