Joe Moore's blog



Joe MooreJoe Moore
Standup 06/25/2007
edit Posted by Joe Moore on Monday June 25, 2007 at 03:40PM

Interesting Things

Joe MooreJoe Moore
Standup 06/21/2007
edit Posted by Joe Moore on Thursday June 21, 2007 at 03:38PM

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.

Joe MooreJoe Moore
Standup 06/19/2007
edit Posted by Joe Moore on Tuesday June 19, 2007 at 08:16PM

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:

Joe MooreJoe Moore
Standup 06/18/2007
edit Posted by Joe Moore on Monday June 18, 2007 at 08:15PM

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 having to_param return the result of id.

Joe MooreJoe Moore
Standup 06/14/2007
edit Posted by Joe Moore on Thursday June 14, 2007 at 08:14PM

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>

Joe MooreJoe Moore
Standup 06/13/2007
edit Posted by Joe Moore on Wednesday June 13, 2007 at 03:59PM

Interesting Things

  • Rails gotcha: Date.parse and Time.parse do 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_to can 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>

Joe MooreJoe Moore
Standup 06/12/2007
edit Posted by Joe Moore on Tuesday June 12, 2007 at 03:38PM

Interesting Things

  • ActionView::Helpers::TextHelper in Rails has some great helper methods for tidying up HTML, including the following, which many of us did not know about:
    • auto_link - Turns all urls and email addresses into clickable links...
    • sanitize - Sanitizes the html by converting <form> and <script> tags into regular text...
  • Sometimes you want to return a response without any content, just header information letting you know what happened. You can do this with the head method 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_tag has a bug: if you give it a file name with a capitalized extension, as some cameras save them, image_tag will 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_to method 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.

Joe MooreJoe Moore
Standup 06/11/2007
edit Posted by Joe Moore on Monday June 11, 2007 at 08:33PM

Interesting Things

  • Rails: fields_for makes 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>

Joe MooreJoe Moore
Standup 06/07/2007
edit Posted by Joe Moore on Thursday June 07, 2007 at 07:16PM

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.

Joe MooreJoe Moore
Standup 06/06/2007
edit Posted by Joe Moore on Wednesday June 06, 2007 at 05:15PM

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: