SameShirtEveryDay.com

Personal blog of the one called Alex Gorbatchev, from Toronto, Canada.
follow me on Twitter

Hidden gem – error_message_on

Posted on June 3rd, 2007 by Alex Gorbatchev. In Rails. 8 comments!

Story goes like this: I was trying to find a way to display form error messages in a pretty tight place. Using your regular error_messages_for creates a pretty long list and makes my page scroll.

Turns out, ActiveRecordHelper has another far much less known method called error_message_on. I thought it was just me at first, but a quick look on Google revealed that error_message_on returns only 3,240 hits where as error_messages_for comes in at 16,200 hits.

Here’s how this looks like in code:

<label for="email">Email <%= error_message_on :user, :email %></label>
<%= f.text_field(:email) %>

And with a little bit of CSS magic this is what the form looks like:

Generate Google sitemap with Rails and RXML

Posted on May 26th, 2007 by Alex Gorbatchev. In Rails, Web Development. 4 comments!

It occurred to me that a good idea would be to add a Google sitemap to Noobkit, especially because it’s using frames. Here’s how I went about it:

In a regular controller I load up all my @packages but instead of a plain sitem_map.rhtml, I have a site_map.rxml file which looks like this:

xml.instruct!
xml.urlset "xmlns" => "http://www.google.com/schemas/sitemap/0.84" do
  xml.url do
    xml.loc         "http://test"
    xml.lastmod     w3c_date(Time.now)
    xml.changefreq  "monthly"
  end
  @packages.each do |package|
    xml.url do
      xml.loc         "http://www.noobkit.com/page/ref/#{package.full_name}"
      xml.lastmod     w3c_date(package.created_at)
      xml.changefreq  "monthly"
    end
  end
end

w3c_date goes into your_controller_helper.rb.

def w3c_date(date)
  date.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00")
end

That’s all to it. Packages provide entry points to their entire API trees and should be enough information for Google to start crawling there.

Announcing Noobkit Docs

Posted on May 24th, 2007 by Alex Gorbatchev. In Rails, Ruby. No comments yet...

Last week I saw a post by Rob Sanheim about sucky Rails documentation. I don’t know why, but I got seriously inspired and started playing around with RDoc.

4 hours later, I had RDoc generator importing everything into a database and a few hours later it was completely browse-able.

After that, it’s was all the matter of picking a name (seriously, I used it) and making a pretty CSS for it.

So today I’m finally getting this baby public and I give you:

Noobkit Docs. Ruby on Rails documentation… on Rails.

I’ve got big plans for the upcoming releases. This is the first iteration to get the foot out of the door without feature creep.

Please help me get the word out and digg it :)

Zlib:BufError while installing Capistrano on Windows

Posted on May 22nd, 2007 by Alex Gorbatchev. In Rails, Ruby. No comments yet...

It’s time to dive into Capistrano and I can’t find any good get started tutorial.

Funny enough, I couldn’t even gem install capistrano. Apparently, on Windows, it’s common to be getting ERROR: While executing gem … (Zlib::BufError) buffer error.

To fix the problem I had to run gem update --system. Twice, because the first time it failed.

Thnx to don’t repeat yourself.

JavaScript CSS exploit in Internet Explorer

Posted on May 15th, 2007 by Alex Gorbatchev. In JavaScript, Rails. No comments yet...

This issue allows an attacker to insert inject random JavaScript code which could potentialy be very harmful. It’s the same exploit that was used by the MySpace Worm. If you are using sanitize(), this is something to be aware of.

sanitize("<div style=\"width: expression(alert('gotcha'))\">pure innocence</div>")

Causes an infinite loop alert box in IE 7. Currently applies to Ruby on Rails 1.2.2.

home
Subscribe to this blog Follow me on Twitter My bookmarks on Delicious My photography on Flickr