Couple of quick tips for creating content meant for mobile devices using Ruby on Rails:
- You’ll probably want to setup a new default layout for all templates. You can do that by creating app/views/layouts/application.rhtml and populating it with whatever you want your default layout to be. For instance here’s an unstyled version of the mostest simplest template that Luca posted with GAP as a default rhtml layout:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Valentine</title> </head> <body> <%= @content_for_layout %> </body> </html>
- Adaptation of the content type based on the mime types the device claims to accept is also pretty much a necessity. I’m going off the MIME types post pointed to from GAP for this also in creating an ApplicationController that sets content type based on the accept header sent by the browser:
class ApplicationController < ActionController::Base before_filter :set_content_type def set_content_type if @request.accepts.include?( Mime::Type.parse( 'application/vnd.wap.xhtml+xml' ) ) type = 'application/vnd.wap.xhtml+xml' elsif @request.accepts.include?( Mime::Type.parse( 'application/xhtml+xml' ) ) type = 'application/xhtml+xml' else type = 'text/html' end @headers["Content-Type"] = type + "; charset=utf-8" end end
The order for the checks I’m sure is something that just about everyone will have their own opinion about, so I stuck with what that post had.