Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts

2008-05-29

Rails, Simile Timeline and Pocket IE

Following on from earlier, I ran into another problem with my little test application but, thankfully, it ended up being easy to fix.

In the application I make use of Timeline. Including it in the application is simple enough. I just include this:

javascript_include_tag(
"http://simile.mit.edu/timeline/api/timeline-api.js" )
in the html.erb file and the Timeline is available for use (I'll probably go with a local version at some point soon, I've just not got around to sorting that out yet).

The problem I ran into is that Pocket IE on my Pocket PC (a Dell Axim X50) doesn't seem to like this and throws an "Object Error". This was easy enough to solve in the end. I simply added this:
# Test if the request came from Pocket IE.
def pocket_ie?( request )
request.env[ "HTTP_USER_AGENT" ][ /MSIE.*Windows CE/ ]
end
to my ApplicationHelper class and then, in the html.erb file, simply said:
unless pocket_ie?( request )
javascript_include_tag(
"http://simile.mit.edu/timeline/api/timeline-api.js" )
end
Combined with a handheld specific stylesheet to hide the div that contains the timeline I end up with a version of the page that works in Pocket IE with no problems.

Okay, I guess it's a little kludgy, but it works and solves the problem at hand.

Ruby on Rails (and some WAP)

I'm quite a fan of ruby and have been for many years. In the last year or so I've been meaning to get to grips with rails but, every time I've tried, we've ended up having a falling out.

Most of the reasons have tended to be based around the (it seems to me) amazing lack of useful documentation. Sure, there's lots of stuff out there that documents the framework, but the sort of documentation that helps ease you into the learning process seems very thin on the ground.

Not too long back, at the suggestion of Rich Daley, I invested in a copy of Agile Web Development With Rails. This was just the sort of thing I was looking for and it's been a huge help (and also a huge source of frustration in itself seeing as how it's aimed at an earlier version of rails than the one I've got installed, but I've managed to get over that hump — it also seems that there's a third edition on the way).

Even with that book I still had a couple of aborted attempts to get to know rails better. As often happens with me the problem really came down to not having a goal to work to, a problem to solve, an application to build. Finally, last week, I devised a problem to solve and set to work.

And it worked, and it's been enjoyable. So far I'm impressed.

For me a good development system is one where my needs have been anticipated and, up until now, rails seems to deliver. A good example happened very recently. After having "finished" my little test application I thought it might be fun to add some simple WAP support. I imagined it would be easy enough using respond_to. Something like this:

def index
respond_to do |format|
format.html
format.wml
end
end
However, that didn't work. rails didn't know what to do with a "wml". A quick Google search later (see, the online docs are fine once you know what you're doing) and I found that all I needed to do was to edit my config/environment.rb to add the following:
Mime::Type.register "text/vnd.wap.wml", :wml
A restart of the server later and everything was fine. All I then needed to do was to create a index.wml.builder along the lines of this:
xml.instruct! :xml, :version => "1.0"

xml.wml "xml:lang" => "en-gb" do

xml.card :title => "My title here" do

xml.p "Something interesting here"
xml.p "Something else interesting here."

end

end
and I was done (and testing was easy enough thanks to the wmlbrowser add-on for Firefox).

I think I'm going to like rails. Now to find a real problem that needs solving...