In the "bugs that drive me crazy" category are two that I've recently discovered when I upgraded to the new iPhone 4. Both look like examples of programmers writing software from the comfort of their cushy high-speed internet connections and not testing in the real world. Both involve disappearing data – unbelievably frustrating.
Here's a common pattern and good rails thing to know about: read_attribute(:symbol)
Basically what it does is read the attribute from the object's database field, even if you have over-ridden the name of that attribute with a virtual attribute of the same name.
When using Paperclip to save an attached image, how do I get & store the dimensions of the image? Best way is to create two fields to store the width & height and then just populate those fields when the image loads. (Other solutions, like reading it dynamically each, incur a lot of unnecessary disk activity.) Be sure to checkout some basic tutorials on Paperclip if you are unfamiliar with it generally. (see references below 1 2 3)
Step by step instructions.
1. create a new file at lib/paperclip_processors/thumbnail_with_dimensions.rb
2. Paste the contents of this gist into the newly created file:
http://gist.github.com/343678
CSS Positioning cheet-sheet. You actually need quite a bit of understanding of CSS to find this useful. I recommend David Sawyer McFarland's book, CSS The Missing Manual.
OK, so I feel it is officially time to kill IE 6 and below. IE 6 has been the bane of web developers' existence for quite some time now. I say, just kill it. If your product manager whines and says "but we need to support all browsers" insist that they reconsider. Management and product managers don't understand the real cost associated with supporting this awful browser. Many think that it's simply a little more tweaking. It's not. If they truly knew how bad it is they'd understand.
Some experimentation with the text-overflow property.
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<body>
<div style="border: 1px solid red; max-width: 400px; overflow:hidden; text-overflow: ellipsis;">
<nobr>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac libero nec est luctus aliquam. Nulla sodales, dolor a consectetur volutpat, elit mi convallis sem, at ornare ligula odio non metus. </nobr>
</div>
</body>
</html>
Firefox 3.5
Safarai 4
IE 7
A little CSS pattern to demonstrate what to do when you want one column to stay at a fixed width and the other column to stretch horizontally with the window. Thanks to my friend CSS guru Joe Silvashy for this one.
What I want it a column on my right side to be a fixed width, and the column on the left to stretch with the window gracefully (in web terms this is called a "liquid" layout).
I discovered an interesting difference between two patch levels of the same Ruby (1.8.7)
respond_to do |format|
format.html {
super # call the index method of the superclass
}
end
end
This does not produce an error in Ruby 1.8.7 patchlevel 72 (the one that happens to ship with Snow Leopard), but in Ruby patchlevel 249 (the most recent one), it tells me I'm not allowed to do this.
This method was adapted from this blog post.
So, you are creating a thing (record) or maybe you are updating it. You've added created_by and updated_by fields to your model, and you've made these integers with the intention of them both being foreign keys to the Users model.
Maybe you've even setup a belongs_to relationsion to your User model like so:
Quick demonstration of public, private, and protected methods.