Simple Meta Tags with MetaOnRails

Simple meta tag rules (from google webmaster tools):

  1. do not add useless meta tags
  2. add site-wide-unique meta tags
  3. add max 10 keywords
  4. in doubt add no meta tags, search engines will grab something

Obey or be penalized.

For simplicity use: MetaOnRails Rails plugin

Usage

#in your head (no not that head...)
=display_meta

#in your views, add unique keywords/description that matter
set_meta(
  :keywords=> [@movie.category, @movie.genre,@user.name]*' ',
  :description=>@movie.description
)

Output

<meta name="description" content="my description" />
<meta name="keywords" content="my,keyword" />

Parsing RSS Feeds via Googles JS Feed API

So far we parsed our feeds with the acts_as_feed Rails plugin but as long as you only want to show them to users, there is an easier alternative: Googles JS Feed API!

Result

rss feed through google rss api

rss feed through google rss api

(The Example uses jQuery)
Example

<script type="text/javascript" src='http://jqueryjs.googlecode.com/files/jquery-1.3.1.js'></script>
<script type="text/javascript" src='http://www.google.com/jsapi?key=YOUR_API_KEY'></script><script>
google.load("feeds", "1");
$(function(){
  var feed = new google.feeds.Feed("http://rathershort.weblo.gg/rss.xml");
  feed.load(function(result) {
    if (result.error)return;
    $feed = $('#feed_entries');
    for (var i = 0; i < 3; i++) {
      var entry = result.feed.entries[i];
      $feed.append(
        '<div class="home_container_item">'+
          '<h3><a href="'+entry.link+'">'+entry.title.truncate(25)+'</a></h3>'+
          '<div class="small_gray">'+entry.publishedDate.toDate().formatted()+'</div>'+
          '<div>'+entry.contentSnippet.truncate(60)+'</div>'+
          '<br>'+
        '</div>'
        );
      }
    });
  });

//DATE
Date.shortMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Date.prototype.formatted = function(){
  return this.getDate()+' '+Date.shortMonths[this.getMonth()]+' '+this.getFullYear();
};

//STRING
String.prototype.toDate = function(){
  var d = new Date();
  d.setTime(Date.parse(this));
  return d;
};

String.prototype.truncate = function(to_length){
  if(to_length >= this.length)return this;
  return this.substring(0, to_length-3)+'...';
};
</script>

OpenID is complex and limited. Use RPX.

I just finished a RPXNow Rails plugin and gem
so that everyone can enjoy the great usability + simplicity of RPX

Use OpenId / Google / Yahoo / MySpace / Facebook connect transparently through the same interface.

Usage

#login.erb
RPXNow.embed_code('mywebsite',url_for(:controller=>:session, :action=>:rpx_token))

#sessions_controller.rb
def rpx_token
  data = RPXNow.user_data(params[:token],'YOUR RPX API KEY')
  self.current_user = User.find_by_identifier(data[:identifier]) || User.create!(data)
  redirect_to '/'
end

Doing the same with OpenId is impossible, since every provider has his own standards of which fields to supply and how to name them.

Happy login!

Ruby Simple Http Post without NET::HTTP Complexity

I just got brain damage again while trying to use NET::HTTP, its so ridiculous complex, why is there no simple alternative ?
(you can use open-uri for get, but post/delete/update ?)

  def post(url,data)
    require 'activesupport'
    require 'net/http'
    url = URI.parse(url)
    http = Net::HTTP.new(url.host, url.port)
    if url.scheme == 'https'
      require 'net/https'
      http.use_ssl = true
    end
    resp, data = http.post(url.path, data.to_query)
    raise "POST FAILED:"+resp.inspect unless resp.is_a? Net::HTTPOK or resp.is_a? Net::HTTPFound
    return data
  end

I am willing to make a SimpleHTTP gem if no one comes up with a satisfactory solution 😦

SimpleHTTP::get(url,data)
SimpleHTTP::post(url,data)
SimpleHTTP::delete(url,data)
SimpleHTTP::update(url,data)

response = page content, throw exception when response code not 200

UPDATE:
rest-client seems to be a good solution, although it does not support sending files.

Upgrading Ruby from 1.8.6 to 1.8.7 from Source

UPDATE: Just use RVM or install ruby-enterprise-edition, thats far easier …

Just writing this because it took a lot of time to find a working tutorial
Ubuntu Hardy(8.04) has 1.8.6 installed, and Ibex(8.10) already comes with 1.8.7.

sudo apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
tar zxvf ruby-1.8.7-*
cd ruby-1.8.7-*
./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr
make
sudo make install

Hope it helps but so far did not work out for me, when using /usr/bin/local/ruby xxx.rb rubygems are not found, and when installed using –prefix=/usr , openssl is broken, since it is the 1.8.6 version and not even manually installing ruby-1.8.7 openssl seemed to work…