Archive for July, 2007

18th Jul 2007

How-to: Pop-up Menu Selection AJAX in Rails

The problem: In Rails, how do you create a popup menu that calls a given action (to replace a div or whatever else) and passes the selected option as an argument when a new selection is made?

This took me way longer than I thought it would to figure out how to do, so I’m posting the answer here as well for anyone trying to do the same thing.


< %= select_tag :person_choice, options_for_select(@persons),
:onchange => remote_function(:update => “divToBeUpdated”, :with => ‘Form.Element.serialize(this)’, :url => { :action => ‘update_person’}) %>

The key here is the :with => ‘Form.Element.serialize(this)’ option. It’s a bit of magic javascript that passes the selected object along with AJAX call, but I actually don’t really understand it much beyond that. If anyone wants to give me a more thorough explanation, it would be highly appreciated.

Huzzah!
Update: Props to OnRails.org.

Posted by Posted by patrick under Filed under ajax, code, how-to, rails, ruby Comments 1 Comment »

01st Jul 2007

Using Google Apps for Your Domain email on the iPhone

I crumbled and bought an iPhone. Thus far, I love it. It’s the first ’smartphone’ (although the iPhone is more like a ‘geniusphone’) I’ve ever owned, meaning it’s the first that can do email and has unlimited data usage - something we don’t see in Canada.

On first sync, I noticed none of my 3 email accounts worked. I realized right away that it was obvious that both my school and photography emails wouldn’t work, since they were set up to use localhost as the mailserver (since I tunnel them through SSH). My SSL-enabled Google Apps for Your Domain email, however, was not working without reason.

I tapped my way to the settings to discover that the iPhone saw the ‘pop.gmail.com’ server address and assumed I was using a gmail account, so it appended a non-optional ‘@gmail.com’ string to my existing email address, making it look like ‘foo@bar.com@gmail.com’, which was obviously causing the problem.

A couple of other people have run into this problem on the Apple Discussions board as well as the Google Group for the Apps for Your Domain stuff. Thus, I offer a very simple solution:

In Mail.app, change the POP mail server from ‘pop.gmail.com’ to 209.85.199.109, the IP address of the same server. The iPhone won’t recognize it, so it won’t attempt to change it, and everything will work fine.

In addition, I highly recommend changing your username on the iPhone to ‘recent:food@bar.com’, so that Google’s email server knows to send you the most recently received/sent emails, even if they have already been POP’ed off the server by your home machine.

Enjoy your iPhone!

Posted by Posted by patrick under Filed under googleapps, how-to, iPhone Comments 1 Comment »