Musician, Ruby on Rails Entusiast, Composer, Programmer and Lover of Hot Sauce

Installing MySQL Gem after Installing MySQL From MacPorts

Posted: May 25th, 2010 | Author: mindtonic | Filed under: Gems, MySQL | Tags: , , | No Comments »

MacPorts is a fantastic resource for installing and managing libraries on OSX. When working with Ruby on Rails, I installed MySQL (and Postgresql) using MacPorts, but had trouble getting the MySQL gem to install and connect. The error message I received was:

Error: uninitialized constant MysqlCompat::MysqlRes

Here is the magic formula:

sudo gem install -v 2.7 --no-rdoc --no-ri mysql --
--with-mysql-dir=/opt/local/lib/mysql5
--with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config;

Source: http://www.ruby-forum.com/topic/192550


A Better State Machine

Posted: April 19th, 2010 | Author: mindtonic | Filed under: Design Patterns, Rails Plugins, Ruby On Rails | Tags: , , | No Comments »

I have been using AASM as my default State Machine Rails plugin for quite some time. It has always worked great, but now there is a better, more thorough State Machine I recommend. state_machine 0.9 has just been released, and as you can read in this blog post, they are rapidly moving towards the finalization of the 1.0 version. http://www.pluginaweek.org/2010/04/19/state_machine-0-9-0-locked-and-loaded!

What lead me to discover this fantastic plugin was the need to be able to call ActiveRecord observers in relation to the State of an object. With AASM, I had to incorporate my lib class calls in a method that was referenced in a state definition. I didn’t like this because it required my Model to have too much knowledge of the outside world. I think it is a best practice to encapsulate this type of functionality into an observer, leaving the model to be happy in it’s own little world. state_machine accomplishes this by allowing the placement of observer calls using a DSL provided by the plugin.


Converting attachment_fu to Paperclip

Posted: October 1st, 2009 | Author: mindtonic | Filed under: Gems, Ruby On Rails | Tags: , | No Comments »

I am making the transition from attachment_fu to paperclip on a very large project of mine. I wrote the following method, inside of my old attachment_fu model ItemImage to do the work. I wrote it to run from inside the rails console. It gives handy messages out letting you know what happened.

Reference: http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip


Rails Javascript and CSS Compression

Posted: July 30th, 2009 | Author: mindtonic | Filed under: Development, Rails Plugins, Ruby On Rails | Tags: , , | No Comments »

To speed up site loading, there are two great plugins for “compressing” your stylesheets and javascript.

The first is bundle-fu. This plugin does not actually compress the files, but rather combines all of the individual documents into one before shipping it out to the client browser.

$ script/plugin install git://github.com/timcharper/bundle-fu.git

And then you simply wrap your sheet and script calls in the bundle method:

  <% bundle do %>
    ...
    <%= javascript_include_tag "prototype" %>
    <%= stylesheet_link_tag "basic.css" %>
    <%= calendar_date_select_includes "red" %>
    
    ...
  <% end %>

The Second plugin, which actually does compress all of your files, is sbecker’s asset_packager. This one is a lot more involved, so check out the github site for more information.


Available Fields from FeedNormalizer Gem

Posted: July 8th, 2009 | Author: mindtonic | Filed under: Gems | Tags: , , , | No Comments »

The FeedNormalizer Gem does an excellent job of returning a single unified object from many of several different syndicated feed types. This saves you from having to worry about whether you are dealing with an rss, atom or some other kind of feed.

The following is a list of the available fields for both the Feed object itself and the Entries objects associated as articles in the channel.

FeedNormalizer::Feed

  • title
  • description
  • id
  • last_updated
  • copyright
  • authors / author
  • urls / url
  • image
  • generator
  • items / channel

FeedNormalizer::Entry

  • content
  • description
  • title
  • date_published
  • urls / url
  • id
  • authors / author
  • copyright
  • categories

Etags

Etags and last_modified are crucial elements to sending proper request headers if you hope to receive conditional get responses and save yourself some overhead in feed processing. FeedNormalizer does not provide access to these elements as they are actually part of the http response headers, and not the feed itself.

While heavily studying the art of feed processing, I encountered Feezirra and Feedtosis, both excellent libraries for feed processing. My own application required a modified version of their concept, but there was a lot to learn in their code.

Feedtosis uses the HttpHeaders process to collect this information from a Curl::Easy object. I adapted the Feedtosis code to meet my needs like this:

require 'http_headers'

class Feed < ActiveRecord::Base
  def store_header_information
    headers = HttpHeaders.new(curl.header_str)
    self.response_code = curl.response_code
    self.etag = headers.etag unless headers.etag.nil?
    self.last_modified = headers.last_modified unless headers.last_modified.nil?
  end
end

Shoulda Testing With Ultrasphinx

Posted: June 24th, 2009 | Author: mindtonic | Filed under: Rails Plugins | Tags: , , , , | 2 Comments »

I use the Shoulda testing framework for my Rails applications. After installing and beginning to use the Ultrasphinx plugin, I needed to figure out how to configure and run in a testing environment. This blog entry held the answer: Stephen Celis: Testing with Ultrasphinx


Ultrasphinx MySql Location Error

Posted: June 24th, 2009 | Author: mindtonic | Filed under: Rails Plugins | Tags: , , , , | 1 Comment »

After installing all of the necessary elements for Spinx and Ultrasphinx, I began following the instructions from Snax Fauna to get the system up and running.

rake ultrasphinx:configure

worked fine, but I encountered the following error upon attempting to index my models:

rake ultrasphinx:index
...
dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
Referenced from: /usr/local/bin/indexer
Reason: image not found

In my configuration for development, I use the MAMP MySql server. The rake configure command correctly pulled all of the connection information from database.yml, so that was not the problem.

I searched around and finally encountered this solution from Michael Hartl:

$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

It worked brilliantly. Thanks Michael.