<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bill Rowell &#187; Ruby on Rails</title>
	<atom:link href="http://www.billrowell.com/category/development/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.billrowell.com</link>
	<description>Welcome To My World</description>
	<lastBuildDate>Fri, 19 Mar 2010 18:27:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Updating Pagination When Deleting Items with AJAX In Ruby on Rails</title>
		<link>http://www.billrowell.com/2008/04/01/updating-pagination-when-deleting-items-with-ajax/</link>
		<comments>http://www.billrowell.com/2008/04/01/updating-pagination-when-deleting-items-with-ajax/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 02:29:52 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[AJAX]]></category>

		<guid isPermaLink="false">http://www.billrowell.com/2008/04/01/updating-pagination-when-deleting-items-with-ajax/</guid>
		<description><![CDATA[Lately, I seem to be on a tear here with my Ruby on Rails development related posts. I suppose its more for my own documentation, but if it helps someone else out with their own development struggles, even better. Today, I wanted to find a solution to updating pagination using AJAX. My issue was I [...]]]></description>
			<content:encoded><![CDATA[<div class="left" style="margin: 0 10px 0 0;"><img src='http://www.billrowell.com/wp-content/uploads/2008/04/ajax.thumbnail.jpg' alt='Ruby on Rails &#038; AJAX' /><img src='http://www.billrowell.com/wp-content/uploads/2008/03/rails.thumbnail.png' alt='Ruby on Rails' /></div>
<p>Lately, I seem to be on a tear here with my Ruby on Rails development related posts.  I suppose its more for my own documentation, but if it helps someone else out with their own development struggles, even better.</p>
<p>Today, I wanted to find a solution to updating pagination using AJAX.  My issue was I use AJAX to update the DOM to remove an item when its deleted.  However, the pagination doesn&#8217;t update and the listings don&#8217;t adjust as you delete them from the middle of the list.  My solution, while not rocket science, I think is pretty cool.  Basically, just keep using AJAX!</p>
<p>The first thing I need is a div to encapsulate my list.  Something like:</p>
<pre style="margin: 0pt 0pt 10px; width: 350px;"><code style="font-size: 10px;">
     &lt;div id="my_list"&gt;
          <%= render :partial => "items", :collection => items %>
          <%= will_paginate items, :renderer => 'ItemLinkRenderer' %>
     &lt;/div&gt;
</code></pre>
<p>Obviously, that&#8217;s my original list inside the <code>my_list</code> div.  I&#8217;ll get to what ItemLinkRenderer is in a big.</p>
<p>I delete my items from the list by updating the dom from within the delete action.  So, something like this:</p>
<pre style="margin: 0pt 0pt 10px; width: 350px;"><code style="font-size: 10px;">
    @item = Item.find(params[:id])
    if !@item.nil?
        @item.destroy
        render(:update) { |page|
            page.remove dom_id(@item)
        }
    end
</code></pre>
<p>This should look pretty straight forward.  Delete the item from the database, then remove it from the current document.</p>
<p>But what about updating the pagination and the list?  We can remove an item, but how do we adjust the displayed list?  Well, just fetch the list of items again.</p>
<pre style="margin: 0pt 0pt 10px; width: 350px;"><code style="font-size: 10px;">
    @items = Item.paginate :all, :page => params[:page], :per_page => 10
    if @items.length > 0
        page.replace_html "my_items", :partial => "items", :locals => {:items => @items}
    else
        page.replace_html "my_items", "&lt;p&gt;You have no items.&lt;/p&gt;"
    end
</code></pre>
<p>Ok, so we can render the items.  But, if you put this in, then start deleting items, you&#8217;ll notice your pagination links get messed up and you have your delete action in the URL.  This isn&#8217;t good, but, like I mentioned earlier, this is where ItemLinkRenderer comes in.  You can define a helper class called ItemLinkRenderer (in item_link_renderer.rb) to render your links properly.</p>
<pre style="margin: 0pt 0pt 10px; width: 350px;"><code style="font-size: 10px;">
    class ItemLinkRenderer < WillPaginate::LinkRenderer
        def page_link_or_span(page, span_class = 'current', text = nil)
            text ||= page.to_s
            if page and page != current_page
                @template.link_to text, :controller => "items", :action => "list", :page => page
            else
                @template.content_tag :span, text, :class => span_class
            end
        end
    end
</code></pre>
<p>This will render your pagination links properly.  Hopefully this works out well for anyone who stumbles upon this.  Let me know if it does or if you find any errors with what I&#8217;ve presented.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billrowell.com/2008/04/01/updating-pagination-when-deleting-items-with-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing &#8220;Child&#8221; Associations in Ruby on Rails</title>
		<link>http://www.billrowell.com/2008/04/01/accessing-child-associations-in-ruby-on-rails/</link>
		<comments>http://www.billrowell.com/2008/04/01/accessing-child-associations-in-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 13:32:49 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.billrowell.com/2008/04/01/accessing-child-associations-in-ruby-on-rails/</guid>
		<description><![CDATA[My good buddy Dan of SecondRotation.com helped me out with a Rails problem last night. I wanted to access the associations defined on an association of one of my model classes when calling find, in essence, accessing a &#8220;child&#8221; association. I looked high and low for this, but with no luck so Dan was able [...]]]></description>
			<content:encoded><![CDATA[<div class="left" style="margin: 0 10px 0 0;"><img src='http://www.billrowell.com/wp-content/uploads/2008/03/rails.thumbnail.png' alt='Ruby on Rails' /></div>
<p>My good buddy <a href="http://enlightsolutions.com/">Dan</a> of <a href="http://secondrotation.com/">SecondRotation.com</a> helped me out with a <a href="http://rubyonrails.org/">Rails</a> problem last night.  I wanted to access the associations defined on an association of one of my model classes when calling <code>find</code>, in essence, accessing a &#8220;child&#8221; association.  I looked high and low for this, but with no luck so Dan was able to come to my rescue.  He said you can do this:</p>
<pre style="margin: 0pt 0pt 10px; width: 350px;"><code style="font-size: 10px;">
@collection = MyClass.find(:all, :conditions => ["id = ?", params[:id]],
      :include => [:foo => [:bar]], :order => sort)
</code></pre>
<p>I guess using <code>:include</code> like this is will tell Rails and ActiveRecord that you want to include the Bar class association in the JOIN you&#8217;re doing in SQL so you can enhance your query.  Makes sense, but too bad it seems to be hardly documented!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billrowell.com/2008/04/01/accessing-child-associations-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AJAX Pagination and Sorting in Ruby On Rails</title>
		<link>http://www.billrowell.com/2008/03/25/ajax-pagination-and-sorting-in-ruby-on-rails/</link>
		<comments>http://www.billrowell.com/2008/03/25/ajax-pagination-and-sorting-in-ruby-on-rails/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 01:06:24 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.billrowell.com/2008/03/25/ajax-pagination-and-sorting-in-ruby-on-rails/</guid>
		<description><![CDATA[I recently decided the account section of a Rails application I&#8217;m working on will be completely AJAX. Every link the user would click on would just replace a section of the account page giving them the impression that they&#8217;ve never left their account section because the URL isn&#8217;t changing. However, I needed to do pagination [...]]]></description>
			<content:encoded><![CDATA[<p>I recently decided the account section of a Rails application I&#8217;m working on will be completely AJAX.  Every link the user would click on would just replace a section of the account page giving them the impression that they&#8217;ve never left their account section because the URL isn&#8217;t changing.  However, I needed to do pagination and sorting for lists of different things.  So hunting on Google I went.</p>
<p>I first came across <a href="http://railsontherun.com/2007/9/27/ajax-pagination-in-less-than-5-minutes">this article</a> over at <a href="http://railsontherun.com/">Rails on the Run</a> about how to do it with will_paginate, prototype, and low pro.  I mucked around with it for about 30 minutes and definitely had some struggles, so I went back to Google.  I eventually came across <a href="http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links">this article</a> at <a href="http://weblog.redlinesoftware.com/">Redline Software&#8217;s Weblog</a> about an easier way to do it with will_paginate.  The nuts and bolts of it is you can use a helper class to write your pagination links for you very easily (I won&#8217;t steal their code and post it here.  Check out the link to grab it.)! </p>
<p>But I&#8217;m not done yet.  Remember, I also need to be able to sort my lists of data.  So I ran with the same idea presented by Redline Software and came up with this way to write out the anchor tags for my sort links:</p>
<pre style="margin: 0pt 0pt 10px;"><code style="font-size: 10px;">
def sort_remote_url(text, value)
    value += "_reverse" if params[:sort] == value
    @template.link_to_remote text, {:url => params.merge(:sort => value)}
end
</code></pre>
<p>What sort_remote_url does is take in the text for the link and the value of the sort parameter.  When you click on the sort link, it works just like the pagination and updates the current view.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billrowell.com/2008/03/25/ajax-pagination-and-sorting-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting Geographical Based Search Results In Ruby on Rails</title>
		<link>http://www.billrowell.com/2008/03/20/sorting-geographical-based-search-results-in-ruby-on-rails/</link>
		<comments>http://www.billrowell.com/2008/03/20/sorting-geographical-based-search-results-in-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 19:12:36 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.billrowell.com/2008/03/20/sorting-geographical-based-search-results-in-ruby-on-rails/</guid>
		<description><![CDATA[I&#8217;ve spent the last few months on a Ruby on Rails project for a client. I&#8217;m integrating a lot of different applications into it, creating quite the &#8220;mashup&#8221;. One part of the project requires the ability to search the system for results that fit within a radius of a given postal code. So to do [...]]]></description>
			<content:encoded><![CDATA[<div class="left" style="margin: 0 10px 0 0;"><img src='http://www.billrowell.com/wp-content/uploads/2008/03/rails.png' alt='Ruby on Rails' /></div>
<p>I&#8217;ve spent the last few months on a <a href="http://www.rubyonrails.org/">Ruby on Rails</a> project for a client.  I&#8217;m integrating a lot of different applications into it, creating quite the &#8220;mashup&#8221;.  One part of the project requires the ability to search the system for results that fit within a radius of a given postal code.  So to do this, I need some sort of searching algorithm or application and a geocoding application for zip code relationships.  The search results need to be able to be sorted by the different attributes on the results.</p>
<p>So this meant I needed several pieces.  One was a searching module.  I found <a href="http://ferret.davebalmain.com/trac">ferret</a> and the <a href="http://projects.jkraemer.net/acts_as_ferret/">acts_as_ferret</a> Rails plugin to do full text searching.  From what I could gather online, this was one of the best solutions out there.  I want to be able to display distances between zip codes, which I can do using <a href="http://geokit.rubyforge.org/">GeoKit</a>.  So I find myself off and running.</p>
<p>I was able to do everything successfully from getting the right results back to calculating distances (Side note.  If you need a start with acts_as_ferret, there&#8217;s a good article <a href="http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial">here</a> at <a href="http://www.railsenvy.com/">Rails Envy</a>).  However, because the distances between zip codes are calculated and not part of the ferret index, I can&#8217;t sort by results.  Uh oh&#8230;</p>
<p>The solution was, in my opinion, a hack, but it works.  What I did was let acts_as_ferret handle sorting for everything except distances (it couldn&#8217;t do it anyway, so fine).  After I get my results back, I decided, well, I guess I can sort them again, right?  So, let&#8217;s do this:</p>
<pre style="margin: 0 0 10px 0;"><code style="font-size: 10px;">
@total, search_results = MyModel.full_text_search(@search_term,
  {:sort => s},
  {:include => [:zip_code],
    :conditions => conditions})
</code></pre>
<p>This gets me my search results.  What about distances?  Well, this can be done, even though its an issue performance wise:</p>
<pre style="margin: 0 0 10px 0;"><code style="font-size: 10px;">
for sr in search_results
   sr.destination_distance = round_to(sr.zip_code.distance_to(@search_zip_code), 2)
end
</code></pre>
<p>So now each result knows what its distance is from the searched upon zip code.  Now what about sorting?</p>
<pre style="margin: 0 0 10px 0;"><code style="font-size: 10px;">
if params[:sort] == "distance"
    search_results = search_results.sort
    @total = search_results.length
elsif params[:sort] == "distance_reverse"
    search_results = search_results.sort
    search_results = search_results.reverse
    @total = search_results.length
end
</code></pre>
<p>So now you&#8217;re thinking, ok, but how do you know how to sort MyModel?  Easy, I decided I&#8217;d override <=> for the MyModel class so that a MyModel was less than, greater than, or equal to another MyModel based on distance.  So I did this:</p>
<pre style="margin: 0 0 10px 0;"><code style="font-size: 10px;">
def <=>(item)
    if self.destination_distance < item.destination_distance
      return -1
    elsif self.destination_distance > item.destination_distance
      return 1
    else
      return 0
    end
end
</code></pre>
<p>So you can see with the example above, I can sort by just calling sort.  To reverse the sort, just call reverse after sorting.
</p>
<p>So there you go, sorting by distance values.  There are definitely drawbacks with this method.  First, you have to iterate over <strong>all</strong> of the search results to set the distance on them.  Second, what if I need to sort by some other calculated value?  Since I overroad <=> for distance, I can&#8217;t really do it for another value.  But for now, this works.  Maybe I, or someone else, can come up with a better solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billrowell.com/2008/03/20/sorting-geographical-based-search-results-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploading and Resizing Images in Ruby on Rails</title>
		<link>http://www.billrowell.com/2008/03/15/uploading-and-resizing-images-in-ruby-on-rails/</link>
		<comments>http://www.billrowell.com/2008/03/15/uploading-and-resizing-images-in-ruby-on-rails/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 19:27:30 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.billrowell.com/2008/03/20/uploading-and-resizing-images-in-ruby-on-rails/</guid>
		<description><![CDATA[In my previous article on using ImageMagick and Mini-Magick to manipulate images in Ruby on Rails, I talked about how to install all of the goodies you&#8217;d need to work with images in Rails. I thought I&#8217;d expand on this a little bit more and give an example on how I used this cool stuff [...]]]></description>
			<content:encoded><![CDATA[<div class="left" style="margin: 0 10px 0 0;"><img src='http://www.billrowell.com/wp-content/uploads/2008/03/logo.jpg' alt='ImageMagick' /></div>
<p>In my previous article on using <a href="http://www.billrowell.com/2008/02/20/ruby-on-rails-image-maniuplation-with-imagemagick-and-mini-magick-on-os-x/">ImageMagick and Mini-Magick to manipulate images in Ruby on Rails</a>, I talked about how to install all of the goodies you&#8217;d need to work with images in Rails.  I thought I&#8217;d expand on this a little bit more and give an example on how I used this cool stuff to upload images and resize them in my Rails application.</p>
<p>You&#8217;ll need to set up some HTML code to upload the file to the server.  Something like this will suffice:</p>
<div style="font-size: 80%; width: 550px;"">
<pre style="font-size: 10px; margin: 0 0 10px 0;"><code>
<% form_tag :action => 'upload', :multipart => true, :id => 'upload_form' do -%>
     &lt;input style="margin-left: 5px;" type="file" id="imageone_file" name="imageone[file]" /&gt;
<% end -%>
</code></pre>
</div>
<p>Now you&#8217;ll want to build a model (based on ActiveRecord or not) to save your image for you.  For my use, I did based my image model on an ActiveRecord class since I wanted to at least store the file name of the image in my database.  But doing that is up to you.  Anyway, on to saving the image.  In your class, you want to grab the data for the image file in the posted form and save it to the file system.  Something like this will suffice:</p>
<pre style="font-size: 10px; margin: 0 0 10px 0;"><code>
def image_save(file)
    @file = file
    @content_type = file.content_type.chomp
    @original_filename = base_part_of(file.original_filename)
    @extension = @original_filename[@original_filename.rindex(".") .. @original_filename.length].strip.chomp

    self.file_name = "#{epoch_time()}#{@extension}"

    is_saved = false
    begin
      if self.file
        if self.content_type =~ /^image/
          # Make the directory for the id of the listing if it doesn't exist
          Dir.mkdir("#{RAILS_ROOT}/public/images/originals/") unless File.exists?("#{RAILS_ROOT}/public/images/originals/")

          # What's the new file name?

          # Create the temporary file
          File.open("#{RAILS_ROOT}/public/images/originals/#{self.file_name}", "wb") do |f|
            f.write(@file.read)
            f.close
          end

          # Crop the image to the sizes we need
          crop()

          is_saved = true
        end
      end
    rescue
    end

    return is_saved
end
</code></pre>
<p>So what are we doing here?  First, we grab the content type of the file, its original file name, and the extension of the file.  We save this information out to attributes defined on the model itself, i.e.</p>
<pre style="font-size: 10px; margin: 0 0 10px 0;"><code>
attr_accessor :file, :content_type, :original_filename, :extension
</code></pre>
<p>Then we check to make sure the directory where we want to save the original file exists, and if not, create it.  Then we save the file itself.  Once we have the file saved, you&#8217;ll notice I call a method called crop().  This is my method that resizes the original image and saves the resized images to the file system.  How do I do that?  Check this out:</p>
<pre style="font-size: 10px; margin: 0 0 10px 0;"><code>
  def crop()
    image = MiniMagick::Image.from_file("#{RAILS_ROOT}/public/images/originals/#{self.file_name}")
    if !image.nil?
      # Resize to 360x360
      image.resize "360x360"
      image.write("#{RAILS_ROOT}/public/images/360x360/#{self.file_name}")

      # Resize to 240x240
      image.resize "240x240"
      image.write("#{RAILS_ROOT}/public/images/240x240/#{self.file_name}")

      # Resize to 120x120
      image.resize "120x120"
      image.write("#{RAILS_ROOT}/public/images/120x120/#{self.file_name}")

      # Resize to 80x80
      image.resize "80x80"
      image.write("#{RAILS_ROOT}/public/images/80x80/#{self.file_name}")

      # Resize to 40x40
      image.resize "40x40"
      image.write("#{RAILS_ROOT}/public/images/40x40/#{self.file_name}")
    end
  end
</code></pre>
<p>As you can tell, I needed several different image sizes.  You start with the lowest size and work your way down.  Not doing this gets you funky sized images.  <a href="http://rubyforge.org/projects/mini-magick">MiniMagick</a> makes it really easy to just open the file and set the new size for the image and then just write it out to where you want it.  Nice!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billrowell.com/2008/03/15/uploading-and-resizing-images-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Image Manipulation with ImageMagick and Mini-Magick on OS X</title>
		<link>http://www.billrowell.com/2008/02/20/ruby-on-rails-image-maniuplation-with-imagemagick-and-mini-magick-on-os-x/</link>
		<comments>http://www.billrowell.com/2008/02/20/ruby-on-rails-image-maniuplation-with-imagemagick-and-mini-magick-on-os-x/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 01:39:29 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.billrowell.com/2008/02/20/ruby-on-rails-image-maniuplation-with-imagemagick-and-mini-magick-on-os-x/</guid>
		<description><![CDATA[I&#8217;m working on a Ruby on Rails project that requires users to be able to upload images. At the same time, we want to resize images so that they appear as we want them to on site. To do this, I found that the best solution would be to use the Ruby Gem Mini-Magick which [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a Ruby on Rails project that requires users to be able to upload images.  At the same time, we want to resize images so that they appear as we want them to on site.  To do this, I found that the best solution would be to use the Ruby Gem Mini-Magick which uses ImageMagick.  The benefits of using Mini-Magick is that its lighter weight that just using RMagick.  So away I went&#8230;</p>
<p>I develop my Rails applications on OS X, so I thought I might have most of the stuff already that I&#8217;d need since XCode was installed.  I had ImageMagick installed from a previous PHP project I had worked on, so I figured I&#8217;d just install the Ruby Gem Mini-Magick..  I did and hooked it up to my application.  When running it though, it didn&#8217;t work.  Bummer.  I kept getting cryptic errors like:</p>
<p><code>ImageMagick command (identify "/tmp/minimagick99445-0.jpg") failed: Error Given 256</code></p>
<p>Great, what does that mean?  So I did some sleuthing on Google and didn&#8217;t have much luck for about an hour or so.  Then I came across <a href="http://www.mattking.org/2007-06/how-to-install-imagemagic-from-source-on-os-x.html">this post</a> at <a href="http://www.mattking.org/">MattKing.org</a>.  How could I have missed this?  A no brainer that you need to have the image libraries installed before compiling ImageMagick (and thus mini-magick).</p>
<p>So with out further ado, here are the steps you need to perform to get this to work!</p>
<h3>Step One &#8211; Download Image Libaries</h3>
<p>Before compiling and installing ImageMagick, you need to have all of the image libraries installed for the image types you want to manipulate.  In my case, I wanted to support JPG, GIF, PNG, and TIFF.  So I had to install the following libraries:</p>
<ul style="margin-left: 15px; list-style: none;">
<li><a href="http://www.ijg.org/files/jpegsrc.v6b.tar.gz">JPEG</a></li>
<li><a href="http://www.libpng.org/pub/png/libpng.html">LibPNG</a></li>
<li><a href="http://www.linuxfromscratch.org/blfs/view/svn/general/giflib.html">GifLib</a></li>
<li><a href="http://www.linuxfromscratch.org/blfs/view/svn/general/libtiff.html">LibTiff</a></li>
</ul>
<p>Once you have those downloaded, you can go on to Step 2</p>
<h3>Step Two &#8211; Install Image Libraries</h3>
<p>Now that you have all of the image libraries downloaded, its time to install them.  Extract them using tar and install them!</p>
<div style="margin-left: 15px">
<h4>JPEG</h4>
<p><code>tar xzvf jpegsrc.v6b.tar.gz<br/>cd jpeg-6b<br/>./configure<br/>make<br/>sudo make install<br />
</code></p>
<h4>LibPNG</h4>
<p><code]>tar xzvf libpng-1.2.24.tar.gz<br/>cd libpng-1.2.24<br/>./configure<br/>make<br/>sudo make install<br />
</code></p>
<h4>GifLib</h4>
<p><code>tar xzvf giflib-4.1.4.tar.gz<br/>cd giflib-4.1.4<br/>.configure<br/>make<br/>sudo make install<br />
</code></p>
<h4>LibTiff</h4>
<p><code>tar xzvf tiff-3.8.2.tar.gz<br/>cd tiff-3.8.2<br/>.configure<br/>make<br/>sudo make install<br />
</code>
</div>
<h3>Step Three &#8211; Download &#038; Install ImageMagick</h3>
<p>With all of the image libraries installed, you can download <a href="ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz">ImageMagick</a>.  I installed mine to the /usr/ directory, but I think /usr/local/ would work as well.</p>
<div style="margin-left: 15px;">
<code>tar xzvf ImageMagick-6.3.8-9.tar.gz<br/>cd ImageMagick-6.3.8<br/>./configure --prefix=/usr/<br/>make<br/>sudo make install<br/></code>
</div>
<p><br/></p>
<h3>Step Four &#8211; Install ImageMagick</h3>
<p>You&#8217;re almost there!  Now that you have all of the image libraries installed and ImageMagick installed, you can go ahead and install the Ruby gem Mini-Magick</p>
<p><code style="margin-left: 15px;">sudo gem install mini_magick</code></p>
<p>One note that I found very helpful on Matt King&#8217;s blog post was to check to make sure the configure script for ImageMagick could find the image libraries you wanted to be able to use.  Check the output at the end of the configure script and make sure <strong>yes</strong> is present next to each image library you want to use.</p>
<p>You should be ready to rock now!  To use mini-magick, insert the following lines into your environment.rb file:</p>
<div style="margin-left: 15px;">
<code>require 'rubygems'<br/>gem 'mini_magick'<br/>require 'mini_magick'</code>
</div>
<p><br/></p>
<p>Now that you&#8217;re all set up, you can load up a file and do whatever you want to it using Mini-Magick.  Perhaps something like this!</p>
<div style="margin-left: 15px;">
<code>filename = "path to your file"<br/>fileout = "path to output file"<br/>image = MiniMagick::Image.from_file(filename)<br/>image.resize "120x120"<br/>image.write(fileout)</code>
</div>
<p><br/></p>
<p>There you go!  If something doesn&#8217;t work, the first thing I&#8217;d check is to make sure all of the libraries and ImageMagick were installed properly.  Also check file permissions in case for some reason the directory you&#8217;re trying to save your file is locked down so the web server user can&#8217;t write to it.</p>
<p>One more side note before I finish.  I was able to use these <strong>exact</strong> steps to install ImageMagick and Mini-Magick on my <a href="http://debian.org/">Debian</a> server which I&#8217;m using for my public test environment.  So, that cool thing about using these steps installing everything from source allows you to duplicate on other *NIX systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billrowell.com/2008/02/20/ruby-on-rails-image-maniuplation-with-imagemagick-and-mini-magick-on-os-x/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->