http://blog.logeek.fr/2008/12/23/how-to-freeze-gems-with-rails-2-1
Paperclip/ImageMagick/RMagick error: “is not recognized by the ‘identify’ command”
December 30th, 2009 by e-thang No comments »If you’re using the above combination, and you’re getting the above error, make sure that you’ve configured Paperclip to find ImageMagick in the right place. Create an initializer file, RAILS_ROOT/config/intializers/paperclip.rb, and put “Paperclip.options[:image_magick_path] = ‘path/to/image_magic’” inside of it. On Mac or a *nix system, type “which identify” to find the right folder.
Big thanks to avit on this forum for the solution.
shoulda and factory_girl not cleaning up db between tests
December 22nd, 2009 by e-thang 2 comments »Wow, this one was a doozy. I recently (yesterday) had my first introduction to shoulda and factory_girl for testing. I’m torn as to whether or not fixtures are the root of all evil, as I haven’t really encountered problems with them and find them very simple to use and maintain, but that isn’t the point of this post.
The point is that just starting a new job I figured a good thing to do was first run the unit tests to make sure I had set up the app properly. I was treated to many failures and investigated why. I found many failures caused by a polluted database. Previous tests weren’t cleaning up after themselves, so later tests had bad state (duplicate records and that sort of thing). While that may be a plug for database level enforcement of that kind of rule, that task was beyond the scope of what I was doing.
I scoured Google looking for answers, and a day later I finally found it. Just to stretch you along even further, here’s what it wasn’t:
- shoulda not running implicit teardowns
- transactional fixtures being turned off
No, it was a great deal dumber than that, and a thanks to Eric Artzt, whoever you are, for providing the solution. The table that was giving me fits is a MyISAM table, which doesn’t support transactions. Which means there are no rollbacks to clean up my DB state. Which means I either have to explicitly put calls to do that into an explicity-define teardown method or switch the engine on the table in question.
Installing Ruby gems that require building native extensions on Snow Leopard
December 18th, 2009 by e-thang No comments »I haven’t tested this on all “machines” running Snow Leopard, but on the brand new one I had to get today for work, I found that the default Ruby / Gems install doesn’t support installing gems that require building native extensions. The error message I was treated to contained the following:
MacBook-Pro-de-Ethan-Garofolo:~ juanpaco$ sudo gem install thin
Password:
Building native extensions. This could take a while...
ERROR: Error installing thin:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install thin
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.10 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.10/ext/gem_make.out
The solution was hyper-intuitive. Install XCode. Because of course that's the first thing you think of.
Renaming a database in Rails
December 14th, 2009 by e-thang No comments »Hooray for a non-rant post!
The heart of this method works outside of Rails, but there’s one particular convenience method that Rails provides. Find some way to mimic that behavior, and the rest would apply. Also, this is a MySQL-specific solution. I haven’t tried it with any other DB systems.
We “rename” a database by moving all of its tables into a new database. We do so via MySQL’s RENAME TABLE command. Basically, create an empty database with the new name. We then use our ActiveRecord connection’s “tables” method to loop over all the tables in our database, executing a RENAME TABLE from the old to the new with each iteration. “Tables” is the convenience method I mentioned above. Encapsulating this in a method we get:
def rename_database(old_db_name, new_db_name)
ActiveRecord::Base.connection.execute "CREATE DATABASE #{new_db_name}"
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.execute
"RENAME TABLE #{old_db_name}.#{table} TO #{new_db_name}.#{table}"
end
ActiveRecord::Base.connection.execute "DROP DATABASE #{old_db_name}"
end
Error checking is left as an (important!) exercise to the reader. Also, you may prefer to monkey patch this into ActiveRecord itself as opposed to some odd method floating around in global space.
Also, this presupposes that the new database destination will be on the same server.
SubSonic Post 1
November 29th, 2009 by e-thang No comments »I’m trying out SubSonic for my personal finance management tool, Budgeteer, that I’m creating. The experience thus far has been frustrating. I’m quite keen on straightforward documentation. The creators of SubSonic are not. They are quite keen of being “clever.”
Take for example the first bit you’re likely to read at SubSonic’s webpage, bit which I presume is meant to explain what SubSonic does. “SubSonic is A Super High-fidelity Batman Utility Belt that works up your Data Access…” I like Batman, especially since Christopher Nolan rebooted the franchise. But I don’t care about Batman with relation to software projects. I still don’t really know what SubSonic is after having read that. Is it an ORM? Is it a set of functions similar to MySQL access in PHP? I don’t know, and they don’t seem to want to tell me.
I can stomach cleverness to about the same degree I can stomach horseradish. It ought to enhance the content, and it can in the right hands. The SubSonic authors WAY overdo it, and their writing style hides all the content behind a shroud of utter nonsense. Hopefully they code better than they write English (a common engineering foible shared by this author as well).
They also use a LOT of screencasts. Screencasts have their place, when done well (example). However, the 1 that I’ve looked into up to this point goes on about how easy it is to set up SubSonic while scrolling past they code the author is adding after about 1 second. Screencasts don’t have the best pause mechanism, so it’ s pretty easy to miss what the author is typing. You also can’t copy/paste from a screencast.
More will follow. Since there isn’t actually anything useful on how to set SubSonic up in a client application, and that’s what I’m writing, I’ll do that once and if I figure it out. The frustration had risen to a point where I needed to vent, and where better than the solitude of a blog?
Convenience fees and the nature of government
October 22nd, 2009 by e-thang 1 comment »I cannot understand how government entities operate. Actually, I can– deficits.
BUT, point is, renewing car registration costs an extra dollar if you mail it instead of going in person. That used to be a 20 mile drive, but is now only 10 or 15. If you do it online, $3 extra. So, it’s worth $1 to avoid all that driving for myriad reasons. That would be a kick below the belt for the planet too– 40 miles just to buy a sticker.
City water/trash utility, $1.95/month to pay online instead of mailing it. They call it a “convenience fee.” They don’t call it, “cover our costs of operating online payments.” It’s a fee because online payments are convenient. What if I punch myself in the face while paying online? Will that wave the fee?
I don’t get this. It does cost money to operate payment servers, but a fact of the tech world is that people cost a lot more than hardware. It is cheaper to do online payments. Not only that, but “online” allows for “automatic recurring,” which has been embraced by every entity that actually has to operate in the black, probably because it 1) cuts costs and 2) increases the likelihood of payment occurring on time. It’s an opportunity for a classic win-win.
But that is not the nature of government.
How to tell where your gems are installed
September 16th, 2009 by e-thang No comments »From http://groups.google.com/group/rubypgh/msg/0489eed858e642a0:
gem environment
Type the above. That is all.
Deserves a pizza #3
August 27th, 2009 by e-thang No comments »For helping me figure out why YourSQL stopped working (giving me a “No document could be created” error), my hat is off to oae. It’s a Java thing. YourSQL doesn’t play well with Java 6, which I had set my computer to use. The only thing I could add to oae’s post is that to change the Java settings on OSx, go to Applications->Utilities->Java->Java Preferences. Then drag Java 5 to the top of the list.
So hopefully the 5 visitors I’ve had here will lend me enough Google street cred that this link to your blog brings you .3 visitors.
If you wonder why I was using your sequel or whether or not you had even written the first work requiring a sequel, then I can say with at least .9 certainty that this post doesn’t apply to you.