Joe Moore's blog
Interesting Things
- As mentioned in the 06/19/207 post, Rspec 1.0.6 fixed the Controller-exception-swallowing problem, but now you can't call
flash.stub!(:foo)-- this throws an error. - Check out Google Website Optimizer, which "helps online marketers increase visitor conversion rates and overall visitor satisfaction by continually testing different combinations of site content (text and images)."
- After some research we found that you can cache static web pages in memcache, at least with the Nginx web server, making this a very interesting component of a page caching strategy.
Interesting Things
- RSpec gotcha: Controller errors do not automatically "re-raise" to cause specs to fail in v1.0.5. This is fixed in v v1.0.6.
Interesting Things
- "Do long file uploads lock up Mongrel processes?" Evidence seems to show that, at least with some web servers like nginx, the web server will handle all of the uploading, leaving the Mongrel processes to continue serving. Perhaps Apache does the same?
Ask for Help
- "What is the preferred means for running Ruby/Rails processes on a scheduled basis?" People suggested the following:
- cron/crontab -- our old friend.
- drb -- Distributed Ruby
- Ruby Daemon Module
Interesting Things
- Rails has a handy convention/method-hook for turning an object into an URL parameter: implement
to_param. ActiveRecord already does this by havingto_paramreturn the result ofid.
Interesting Things
Brown-bag lunch topic today: "Smalltalk is dead -- long live Smalltalk!"
Ask for Help
"How can we get a drop-down list/select box to change our browser's URL? We want people to see forum posts from the 'Last 7 Days', so the URL should change when they choose that from the select box." One option is to wrap it in a form and use the
onChange()JavaScript event hook to submit the form:
<code>
<% form_tag(:controller => forum, :action => :filter) do %>
<%= select_tag('recent', options_for_select(filters]), {:onchange => "this.form.submit();"}) %>
<% end %>
</code>
Interesting Things
- Rails gotcha:
Date.parseandTime.parsedo not react the same when passed data that can't be parsed:
<code>
$ script/console
Loading development environment.
>> Time.parse "monkey"
=> Thu Jun 14 08:43:10 PDT 2007
>> Date.parse "monkey"
ArgumentError: 3 elements of civil date are necessary
from /usr/local/lib/ruby/1.8/date.rb:650:in `new_with_hash'
from /usr/local/lib/ruby/1.8/date.rb:695:in `parse'
from (irb):2
>>
</code>
- Rails gotcha #2: in functional tests,
assert_redirected_tocan fail if you are not consistent in your "strings vs symbols" notation. Example:
<code>
class MonkeyWranglersController < ActionController
def index
redirect_to :controller "monkey_wranglers", :action => :list
end
end
</code>
Now, the assertions:
<code> get :index assert_redirected_to :controller => "monkey_wranglers", :action => :list # passes ### get :index assert_redirected_to :controller => "monkey_wranglers", :action => "list" # fails </code>
- More View helpers:
ActionView::Helpers::TextHelper::cyclehelps you with the "every-other-row-should-be-a-different-color" pattern usually seen in tabular data.
Interesting Things
ActionView::Helpers::TextHelperin Rails has some great helper methods for tidying up HTML, including the following, which many of us did not know about:- Sometimes you want to return a response without any content, just header information letting you know what happened. You can do this with the
headmethod on Controllers. For example:head :created, :location => person_path(@person) - Apple's Leopard operating system is due to ship in October, and it will have many nice Ruby and Rails development tools built in, such as Ruby 1.8.6, Ruby on Rails, Mongrel, and Capistrano. Check out the details.
- It seems that Rails'
image_taghas a bug: if you give it a file name with a capitalized extension, as some cameras save them,image_tagwill tack ".png" on to the end. Examples:image_tag("monkey.jpg")# path will have 'monkey.jpg'image_tag("monkey.JPG")# path will have 'monkey.JPG.png'
- Mongrel + Amazon S3: when querying 'buckets' with many files, Mongrel seems to leak memory.
Ask for Help
- "Does Rails'
link_tomethod support nested parameters? The nested parameters seem to be getting squashed together into one long string." This is a known bug in Rails, with an accepted patch that has not been applied.
Interesting Things
- Rails:
fields_formakes it easy to create View form fields for nested objects. For example, from the Rails API Docs:
<code>
<% form_for :person, @person, :url => { :action => "update" } do |person_form| %>
First name: <%= person_form.text_field :first_name %>
Last name : <%= person_form.text_field :last_name %>
<% fields_for :permission, @person.permission do |permission_fields| %>
Admin? : <%= permission_fields.check_box :admin %>
<% end %>
<% end %>
</code>
Interesting Things
- Textile formatter plugin RedCloth 3.0.4 is broken -- it does not format unordered or ordered lists correctly, and does not format paragraph tags correctly, either. Install 3.0.3.
Ask for Help
- "Can you test file uploads using Selenium?" By default, no. There is a Firefox workaround that involves actually changing Firefox's security, and a change to Selenium's code to allow it to type into file path input fields.
Interesting Things
- Rails gotcha: if you want to use a column in the database to order your records, don't name that column "order". Plus, you can get this functionality almost for free by using
acts_as_list, which uses a column named "position." - If you are referencing RFC 822 "Internet Message Format" to do such things as validating the format of an email address, that RFC has been replaced with RFC 2822. The most notable change is that addresses are not valid if they do not specify the top level domain (.com, .net, etc.). Example:
- joe@pivotallabs -- Not valid
- joe@pivotallabs.com -- valid
We had to update validates_as_email to support this. We'll submit a patch.
- Oh yeah... xpath is 1-based, not 0-based. That gets us every time.
Other articles:







