Flowdock

Notes posted by i_am_cam

RSS feed
August 11, 2008
10 thanks

RE: Using validates_format_of to validate URIs

Further to Olly’s note below, you can also specify the protocol to further limit the valid uri’s, else things like ‘ftp ://someurl.com’ (there’s only a space in there to get it to display on here) would be valid.

validates_format_of :uri, :with => URI.regexp(['http'])
August 6, 2008 - (v2.1.0)
1 thank

RE: Using counters with collections

Note that as of Rails 2.1, it’s currently not possible to override the internal counter variable you get when using collections via passing it in through :locals.

This is a useful feature when you have a collection of items rendered but then wish to add another one - most likely via an AJAX request.

I’ve been informed it’s back in Edge, so hopefully it’ll re-appear again in Rails 2.2.

August 6, 2008 - (v2.0.0 - v2.1.0)
1 thank

RE: Cross browser issues

In response to subblue’s note below, you should bear in mind that there may be circumstances where you want an AJAX request to enter the format.html block and not format.js.

When you’re returning HTML content, for example.

By using jQuery’s .ajaxSetup method in such an indiscriminate way (applying it by default to all ajax requests), you make it harder to keep track of what’s returning what.

A better alternative is to use it as a stored function;

function set_content_type_to_javascript(xhr) {
 xhr.setRequestHeader("Accept", "text/javascript");
}

and call this from within your .ajax requests when required;

$.ajax({
 type: "GET",
 url: "/some/url",
 dataType: "script",
 beforeSend: function(xhr) { set_content_type_to_javascript(xhr) },etc…
});