Arthur Chang

Using Paperclip to save an image or file from a url

Paperclip is really good at saving images from local repositories or through forms, but there's little documentation on how to save an image from a remote location, say from a public URL somewhere.

The above uses a quick example using the Flickraw plugin to grab the most interesting photo from Flickr and saving it as a users' favorite photo.

Tagged  //   code   ruby   ruby on rails  

Ruby String Concatenation Escaping

Quick post about something strange I came across recently.  When you concat two ruby strings, it does an extra escape on each string.

The \r\n were double escaped so when you print the string, you don't actually get carriage return or newline characters, you literally get the slash r slash n.  That's all =)

Tagged  //   code   ruby  

Running unit test directly through command line in Rails 2

Testing out some mail receiving stuff, and ran into a problem with just running the script using:

ruby test/unit/mail_receive_test.rb

test/unit/mail_receive_test.rb:1:in `require': no such file to load -- test_helper (LoadError)
    from test/unit/mai_receive_test.rb:1

This was because I was not specifying the test directory in the load path, so simply pass in the test directory with the -I flag, and you'll be golden

ruby -Itest test/unit/mail_receive_test.rb

This was all run while in the rails root directory.

Tagged  //   code   ruby