• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Google AJAX Libraries on Rails ...

If you’re reading this blog you’ve probably already heard about Google’s AJAX Library API on many other news sites like Slashdot.

I’m going to describe my simple process for setting up a RoR app to use Google to pull the APIs in a rails friendly way, throughout layouts, views, and helpers.

First, open up “app/helpers/application_helper.rb”. Here, we are going to add a few tag methods to keep our views clean and also to keep our versions consistent.

def google_loader_tag

  "<script type="text/javascript" src="http://www.google.com/jsapi"></script>"

end

def google_prototype_tag

  google_tag(prototype, 1.6.0.2)

end

def google_scriptaculous_tag

  google_tag( iscriptaculous, 1.8.1)

end

# etc for any of the other libraries

private

def google_tag(name, version)

  "<script type="text/javascript">google.load("#{name}", "#{version}");</script>"

end

Now we need to include these tags in our layouts and views.

In my layout, I put this for a head:

<head>

  <title><%= yield :title %> - My Site</title>

  <%= stylesheet_link_tag amystyle %>

  <%= google_loader_tag %>

  <%= yield :css_include %>

  <%= yield :javascript_include %>

</head>

This lets me specify the page title, CSS, and Javascript, in the view, so we don’t load in anything unnecessary.

Now here is what my view looks like:

<% content_for :title do -%>Welcome<% end -%>

<% content_for :javascript_include do -%><%= google_prototype_tag %><% end -%>

Now my title bubbles up, and my request for prototype bubbles up to the head for me, after the google loader.

The best part about this setup is that my versions will stay the same, and they only need to be changed in one place. And, if I ever decide to host the files locally, I just change the tags in one place, and make the google loader tag return “”, until I fix all of the instances.

source: smartlogicsolutions

 Original Source:

AddThis Social Bookmark Button

Posted at 12:39:54 pm | Permalink | Posted in Google  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Top Stuff

e-messenger

MSN Web Messenger

eBuddy

ASP.NET Ajax CalendarExtender and Validation

AIM Express

Ajax Tools for ASP.NET Developers



About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (176)
  • Ajax (112)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (21)
  • Chat (45)
  • ColdFusion (3)
  • CSS (84)
  • Email (23)
  • Facebook (84)
  • Flash (20)
  • Google (54)
  • Html (29)
  • Image (12)
  • International Calls & VOIP (7)
  • Java (58)
  • Javascript (280)
  • jQuery (200)
  • JSON (75)
  • Perl (2)
  • PHP (172)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (32)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (227)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (29)
  • YUI (13)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange