September 27th, 2007
Now if you’re a regular user of Firefox, you’ve probably already had the opportunity to be dismayed by how you cannot copy and paste text with newlines into the search bar. All you end up with is the first line of text. I just end up typing in the search terms myself or copy and paste line by line.
Try it for yourself with the text here:
First line.
Second line.
Well, all that is gonna go away in Firefox 3, which replaces newlines with spaces. Small change perhaps, but definitely needed in this fanboy’s opinion.
Oh and it works for the Address bar too, only the newlines get removed instead of getting replaced with spaces. Could be useful for multi-line URLs which appear quite often in emails!
September 25th, 2007
Edge Rails now comes with a helper for creating form labels, so in your views, instead of doing this:
<% form_for(:user, @user, :url => user_path(@user)) do |f| -%>
<label for=”user_login”>Login</label>
<%= f.text_field :login %>
<end>
where the <label> is given a for attribute of user_login (since the convention for form input ids is {MODEL_NAME}_{ATTRIBUTE_NAME}), you can instead now do:
<%= label(:user, :login) %>
Quite a bit neater. Makes it easier to explain to beginners how they should use <label>s appropriately since the syntax is similar to the other form helpers. Now give your <label>s proper for attributes if you’re not doing so already.
This makes plugins like this form label helper plugin obsolete.
September 24th, 2007
Converting ActiveRecord instances to their JSON representation has always been a topic that has been dear to me. I’d tried to get a patch that adds to_json to ActiveRecord into Rails (but the quality of my patch was lacking in a few respects). The Jsonifier plugin that I wrote tried to address the lack of built-in JSON serialization by adding a ActiveRecord#to_json method that acts much like ActiveRecord#to_xml.
So it is with mixed feelings when I discovered a couple of days ago when DHH committed a changeset that added a native ActiveRecord#to_json method. Of course, I’m elated that JSON serialization is given first class attention now, since the raison d’ĂȘtre of Jsonifier and my Rails patch was to do just that. A little bit of me is selfishly disappointed since it means that Jsonifier has become quite obsolete!
But it is an excellent change, I look forward to patching it up (if DHH doesn’t beat me to it - there’ve been so much activity on the Rails trunk recently) so that the JSON serializer supports an :include options for including associations much like for ActiveRecord#to_xml and Jsonifier’s mixed in to_json.
Update: I’ve submitted a patch for adding :include to ActiveRecord#to_json. Please test it and give feedback or +1 ;).
September 19th, 2007
Note to self:
When a table column has a default value, such as for the type_category column/attribute like so:
t.string :type_category, :limit => 20, :nil => false, :default => 'tv'
a new instance of your ActiveRecord model will try and set the defaults from the database. Meaning:
Anime.new => #<Anime id: nil, type_category: "tv"...
Courtesy of this in ActiveRecord::Base:
def attributes_from_column_definition
self.class.columns.inject({}) do |attributes, column|
attributes[column.name] = column.default unless column.name == self.class.primary_key
attributes
end
end
So, don’t get confused when your model validations (validates_presence_of :type_category) don’t seem to work when testing:
it "should require a type_category" do
@foo.attributes = valid_foo_attributes.except(:type_category)
@foo.should have(1).error_on(:type_category) # doesn't work since @foo.type_category = 'tv'
end
Explicitly set it to nil or a blank value.
Sounds silly, but it’s a true story.
September 18th, 2007
This is not exactly a new change to Firefox 3’s nightly builds since the bugs have been setting in my browser tab bar for about a week but I figured I’d write about them anyway since it’s quite a nice improvement.
What’s new? Download Resume - now you can pause and resume your downloads in the Firefox Download Manager. Implemented by a Summer of Code student, this brings Firefox’s Download Manager up to speed with Safari (which has a really nice download resume feature that leaves .download files that you can just double-click to resume the download).
You’ll notice the insane speeds (986GB/s) I’m getting too in that last screenshot. Nope it’s not a feature, it’s a bug. And a known one that’s probably fixed if you have a recent nightly.
For Firefox 1.5 or 2 users, don’t despair, extensions like DownThemAll! allow you to resume downloads. If you use an external download manager, you’d probably be more interested in FlashGot.