All posts tagged with Ruby, page 1 of 4
If you override to_param in your model, make sure it doesn't return any Reserved Characters or your nice resource path methods (e.g. artist_path) will throw weird 'failed to generate from' errors.
It would be really helpful if Rails threw an exception that was useful, like 'bad to_param string'; it would have saved an hour of my time at least ;).
12:00 AM on Sunday, 31/01/2010
I managed to wreck my system install of Ruby (the one in /System/Library/Frameworks) on Friday, and needed to re-install the system ruby. This was a difficult and frustrating process, but thanks to my work on the weekend I can share the easy way of installing it.
Note the following assumes you are on 10.6.2 - modify the version appropriately if you're on a different update. Also note that you should take care with this as you will be overwriting your system install of ruby, and also note there is no warranty with these instructions.
First, download Apple's patched ruby source from http://opensource.apple.com/ (select your OS X release, then find ruby in the list of packages and click the download link). Here's a direct link for OS X 10.6.2.
Extract and cd into the directory extracted.
Then run these commands. If you're not on 10.6.2, modify the commands appropriately, and if you're on 32-bit not 64-bit, change x86_64 to i386 (I haven't tested this change but it should work):
mkdir -p /tmp/ruby/Debug
make RC_ARCHS=x86_64 SYSSTRING=universal-darwin10.2.0
sudo make install RC_ARCHS=x86_64 SYSSTRING=universal-darwin10.2.0
sudo cp -R /tmp/ruby/Release/ /
Be very careful with the last command, as it's copying to / using sudo. You will get warning about not being able to overwrite some files, but this doesn't indicate a failure.
This will overwrite your existing system install of ruby, hopefully fixing whatever problem you have.
If you have gems with native extensions you installed or upgraded while you weren't using the system version of ruby, you will need to reinstall those gems.
12:00 AM on Monday, 07/12/2009
I messed up my ruby install on Friday by trying to upgrade ruby to the lates patchlevel of 1.8.7 on Snow Leopard. The ruby upgrade itself went fine, until I tried to use a gem that has native extensions. I decided to just reinstall all the gems that had native dependencies, but man failed with strange undefined errors e.g. the json gem gave "error: ‘ST_CONTINUE’ undeclared (first use in this function)" plus many others.
The fix was to:
sudo -i export ARCHFLAGS="-arch x86_64" gem install <gem_name>
When you install a gem using native extensions, they often use mkmf, which uses have_header, which tries to run a test to see if the header file exists; on Snow Leopard (at least) gcc will fail to compile the test with the error message "gcc-4.2: -E, -S, -save-temps and -M options are not allowed with multiple -arch flags".
There are multiple arch flags by default because the system will compile both an i386 and a x86_64 binary. Re-setting the archflags to only compile x86_64 fixes this.
12:00 AM on Saturday, 05/12/2009
I attended Railscamp Melbourne last week, and it was awesomeawesome (yes, that's awesome to the power of awesome). There were tons of presentations:
- Declare War on Everything with Chaser, by Andrew Grimm (sorry I missed this one, I was getting pwned by the mazes at Ashcombe Gardens).
- Advanced Thinking Sphinx, by Pat A llan (great beard, great man).
- An intro to test-driven development, to produce a working twitter clone called twatter (users are nicknamed twats). Shoutouts to Bodaniel Jeanes and Perryn of ThoughtWorks for this one, it went for about 3 hours but was all the better for it.
- How to be good at rails, by Ryan Bigg (hope your voice is feeling better :)).
- Warden, which is a Rack-based authentication system by Daniel Neighman, and
- Pancake by same; pancake looks like merb slices on steroids, served with strawberries and cream.
- Scrum by Breccan McLeod-Lundy.
- Kanban by Perryn (Perryn was inspired to do this presentation by Breccan's one on Scrum).
- MacRuby by Geoffrey Grosenbach and Marcus Crafter.
- Shells and shell tips, run by Geoffrey as well.
- Introduction to vim by Charles Dale and Andrew France.
- Patching other people's projects with the safety of tests (using the example of adding HTML5 support to Webrat), by Bodaniel Jeanes (again, I missed this due to being stuck in a maze, if it helps I got soaked by rain).
- Video encoding by yours truly; note sweet ruby script that does all the hard work for you.
- Introduction to Gistory and Webstats, also by yours truly (warning: contains dangerous amounts of win).
- Amazing refactoring of Gistory, carried out by Myles, Pat, and Tim Lucas. Myles saw my Gistory introduction, saw the code and immediately started laughing; so they decided to refactor it and then Pat added tests and refactored part of the codebase live. This started around 11-11:30PM and didn't finish till 2AM. I have to say this was my favourite part of railscamp (followed by the intro to testing). MASSIVE shouts to Pat, Myles and Tim for organizing this, and to all who attended for their input.
Big thanks to the posters on the Railscamp Google group, from whom I stole much of the list of presentations, as I have forgotten ;).
This list may be incomplete, and I'm missing the slides for a bunch of them. If you have links, please put them in the comments.
Presentations were just a part of Railscamp though. There was Brains, which took a large part of people's attention. It was pretty awesome seeing everyone work to try and beat each other using ruby, especially on the big screen as it was.
Sunday night was the closing presentations, which let people show off the code they'd been working on over the weekend (this part 'borrowed' from Andrew Grimm [hope you don't mind]):
- Charity ad server
- Codeyak, by the guys from Cogent Consulting
- Zombino by Ryan Bigg
- Word frequency analysis (for the benefit of people learning new languages)
- Let's do stuff!
- Automatic client-side form validations with formtastic and JQuery.
- Publishus and pretty buttons for formtastic
- Rails index - tagging versioning of rails information, by Nigel Rausch
- Painting with Ajax
- Converting an inefficient paper-based system of fostering out pets into a Rails app
- Some sort of couchdb authentication - proxy stack?
- Banana platform game (I love bananas with moustaches) by Carl Woodward
Awesome prizes for the above were donated by a bunch of great sponsors, I can't remember all of them so I won't try :).
And then there was lots and lots of booze.
And there was Werewolf, run by Pat Allan once again; there's nothing like going to bed at 5AM after a long Werewolf session then getting up at 9:30AM to get on the bus back to the airport.
And there's even more, but I think this post is quite long enough so I'll leave it here. If you have links for any of the projects here, please add them in the comments.
(Edited 30 November 2009 to add some people who's names I had forgotten and to correct some info).
12:00 AM on Sunday, 29/11/2009
At work, we are starting to use Multiline step arguments / Scenario outlines in our cucumber tests, but, if you’ve got a lot of data to write as a table, it’s a pain to write the table out by hand. So I whipped up a little ruby script that takes a CSV file and dumps a nicely formatted table of data, suitable for pasting into a cucumber feature.
Grab the CSV to Table converter. Put it in the current directory), and run
ruby csv_to_table.rb <input.csv> and the converted table will be printed to the console.
11:32 PM on Monday, 26/10/2009