<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Hulihan Applications Blog</title>
    <link>http://blog.hulihanapplications.com</link>
    <description>Hulihan Applications - A design and programming firm Specializing in Web, Logo, and Graphic Design and programming, Web Design, Graphic Design, Logo Design, Network Administration/Security/Management and Web Site Hosting. Custom Design and Applications ar</description>
    <language>yourLanguage('en')</language>
    <item>
      <title>Running PHP Inside a Rails App</title>
      <description>&lt;p&gt;Have you ever wanted to run a PHP application inside of a Rails application? Here&amp;#39;s a scenario: your website is written in ruby on rails. You want to run a php application, like &lt;a href=&quot;http://www.magentocommerce.com&quot;&gt;Magento&lt;/a&gt; inside it, under a directory called &lt;strong&gt;shop&lt;/strong&gt;. Since all web-accessible files in Rails are located in the public directory, your shop directory will be located in &lt;strong&gt;public/shop.&lt;/strong&gt; However, whenever you try to access this directory by going to http://www.yourwebsite.com/shop, You get a 500 error from your Rails application saying: Application error&lt;em&gt; &lt;em&gt;Rails application failed&lt;/em&gt; to start properly&lt;/em&gt;, or something along those lines.&amp;nbsp; &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;../images/public_images/application_error.JPG&quot; alt=&quot;Uh Oh.&quot; title=&quot;Uh Oh.&quot; width=&quot;374&quot; height=&quot;86&quot; /&gt;&lt;/p&gt;&lt;p&gt;This is because rails thinks that this subdirectory is a controller or an action within your rails application that isn&amp;#39;t acting properly, when in reality, it&amp;#39;s a real subdirectory with PHP files inside! We need to convince it otherwise. The easiest way to do this is by creating an .htaccess file inside the &lt;strong&gt;shop&lt;/strong&gt; directory. Then paste this code into the .htaccess file:&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
RewriteEngine On
RewriteRule ^([^\.]+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{DOCUMENT_ROOT}/-%2 -d
RewriteRule ^(.*)$ -%2/$1 [QSA,L]
&lt;/pre&gt;

&lt;p&gt;That&amp;#39;s it! Try it again, and your PHP code should run without a problem!&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
      <pubDate>Mon, 08 Feb 2010 22:19:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/27</link>
      <guid>27</guid>
    </item>
    <item>
      <title>WishlistFactory.com</title>
      <description>We recently started a new website called &lt;a href=&quot;http://www.wishlistfactory.com&quot; target=&quot;_blank&quot; title=&quot;WishlistFactory.com&quot;&gt;WishlistFactory.com&lt;/a&gt;, that lets families, friends, and other groups of people to create private wishlists for any event or holiday! It&amp;#39;s a free service, and it&amp;#39;s extremely useful for birthdays and for christmas, and it helps prevent people from getting the same gift twice(or three times, if you&amp;#39;re very unlucky). Check it out!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;text-align: center;background:#B2D6DF;border:1px solid white;padding:10px&quot;&gt;&lt;a href=&quot;http://www.wishlistfactory.com&quot; target=&quot;_blank&quot; title=&quot;WishlistFactory.com&quot;&gt;&lt;img src=&quot;/images/public_images/wishlistfactory.com_logo.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;
</description>
      <pubDate>Wed, 20 Jan 2010 21:47:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/26</link>
      <guid>26</guid>
    </item>
    <item>
      <title>Ruby, Arduino, and Serial Communication</title>
      <description>Lately, We've been using the Programmable &lt;a href=&quot;http://arduino.cc&quot;&gt;Arduino&lt;/a&gt; Microcontroller with some fun projects. We usually program the Arduino to send data to other devices using Serial Communication. Since we also love ruby, we decided to use Ruby to handle all the communications that the Arduino sends to a computer. With this in mind, I thought I'd share a little tutorial of how you can do this. 
&lt;br&gt;&lt;br&gt;
In this example, we're going to program the Arduino to send random data(between 0 and 100) over a serial port to a host computer. On the Host computer, we're going to be running a ruby program that will monitor the serial port and print out any data sent to it on the command line. 

Here's the code(also known as a sketch in arduino lingo) we're going to upload into the Arduino, using the &lt;a href=&quot;http://arduino.cc/en/Main/Software&quot;&gt;Arduino Software&lt;/a&gt;:

&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
/* 
  Feed Simulated data via serial(COM) port to computer.
  This simulated data will be used by a program on the computer to handle serial data from a device.  
*/

void setup() 
{ 
  Serial.begin(9600); 
  Serial.println(&quot;Begin Simulated Serial Data Generation!&quot;); 
} 



int interval_time = 500; // Interval between data being sent. (in ms)
int min_num = 1; // min value to generate data, must be above 1
int max_num = 100; // max value to generate
int sim_data = 0; // initialize data var

void loop() 
{ 
  sim_data = random(min_num, max_num);
  Serial.println(sim_data);
  delay(interval_time); // wait
} 
&lt;/pre&gt;


Then, create a new ruby file with following code(we're going to name our ruby file serial_test.rb). 

&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
 require 'rubygems'
 require 'serialport' # use Kernel::require on windows, works better.

  #params for serial port
  port_str = &quot;COM3&quot;  #may be different for you
  baud_rate = 9600
  data_bits = 8
  stop_bits = 1
  parity = SerialPort::NONE
  
  sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
  
  #just read forever
  while true do
    sp_char = sp.getc
    if sp_char
      printf(&quot;%c&quot;, sp_char)
    end
  end
&lt;/pre&gt;

Then execute the script, and you'll see all the data being sent by the Arduino! Here's what you should be seeing:

&lt;div class=&quot;code_block&quot;&gt;
Begin Simulated Serial Data Generation!&lt;br&gt;
77&lt;br&gt;
35&lt;br&gt;
78&lt;br&gt;
84&lt;br&gt;
86&lt;br&gt;
81&lt;br&gt;
...&lt;br&gt;
&lt;/div&gt;

You can do anything with the data, depending on your what your goal is. In my case, I'm getting sensor data from the Arduino that I display in a pretty &lt;a href=&quot;http://www.fxruby.org/&quot;&gt;fxruby&lt;/a&gt; windows application, then I save the data in a MySQL database for statistical analysis. Fun stuff!</description>
      <pubDate>Mon, 16 Nov 2009 20:13:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/25</link>
      <guid>25</guid>
    </item>
    <item>
      <title>Ruby Random Data Generator</title>
      <description>Here's a quick ruby script that will generate a file full of random data. You may be wondering...why would anyone want a bunch of random numbers? Well, we use this kind of data to make sample graphs in different programs and to simulate data results that a particular piece of hardware should be reporting(like data a sensor would report). We often write software for scientific devices that spew forth tons of data. This script generates example data that such devices might spew, so we know how to handle it on the software side of things. 
&lt;br&gt;&lt;br&gt;
This is a simple ruby script that asks the user for a couple specifications for the data that will be generated. It asks the user for the amount of numbers to generate, the range of values to generate from, the filename to store the data in, and how it should be delimited(comma or newline).
&lt;br&gt;&lt;br&gt;
Here's the code:
&lt;br&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
#!/usr/bin/ruby

# Random Data Generator 
# Author: Hulihan Applications
# Purpose: Uh, To generate random data 
  
def get_keyboard_input(options = {})
  options[:default] ||= &quot;default&quot; # set options[:default]'s  default 
  input = STDIN.gets
  input = input.chomp
  input = options[:default] if (input.size == 0 &amp;&amp; input.to_i == 0) # return the default value if user pressed enter without entering anything.
  return input 
end

# This script generates random data for graphing function. Delimiting options: comma, newline
puts &quot;Generating Random Data...\n&quot;

puts &quot;How Many Numbers do you want to generate?(default is 100)&quot;
@number = get_keyboard_input(:default =&gt; 100)

puts &quot;Number values will be generated randomly What is the Minimum value?(default is 0)&quot;
@min_value = get_keyboard_input(:default =&gt; 0)

puts &quot;Number values will be generated randomly What is the Minimum value?(default is 100)&quot;
@max_value = get_keyboard_input(:default =&gt; 100)

puts &quot;What is the filename to store the data in?(default is data.txt, if file exists, data will be concatenated at EOF)&quot;
@filename = get_keyboard_input(:default =&gt; &quot;data.txt&quot;)

puts &quot;What kind of delimiter would you like, comma or newline?(default is newline)&quot;
@delimiter = get_keyboard_input(:default =&gt; &quot;newline&quot;)

puts &quot;Add tab-delimited ids, yes or no?(default is no)&quot;
@add_ids = get_keyboard_input(:default =&gt; &quot;no&quot;)

puts &quot;Generating #{@number.to_i} numbers between #{@min_value} and #{@max_value}...&quot;

file = File.new(@filename, &quot;a+&quot;)

# generate data
for i in 1..@number.to_i
  if @add_ids.downcase == &quot;yes&quot; || @add_ids.downcase == &quot;y&quot; # add tab-delimited ids
    file.print &quot;#{i}\t&quot;
  end
  file.print rand((@max_value.to_i + 1) - @min_value.to_i) + (@min_value.to_i) # write the random data from a range. We add 1 to @max_value because rand(100) would only give up to 99
  # write delimiter 
  if @delimiter.downcase == &quot;newline&quot;
     file.print &quot;\n&quot;
  elsif @delimiter.downcase == &quot;comma&quot;
     file.print &quot;,&quot; unless i == @number.to_i # add comma unless last value in file
  end
end

puts &quot;File: #{@filename} saved successfully!&quot;
file.close
&lt;/pre&gt;

This script should be ran from command line(in windows, mac os, or linux). Here's an sample of what it looks like when it's running:
&lt;div class=&quot;code_block&quot;&gt;
$ ruby generate_random_data.rb&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Generating Random Data...&lt;br&gt;
How Many Numbers do you want to generate?(default is 100)&lt;br&gt;
1000&lt;br&gt;
Number values will be generated randomly What is the Minimum value?(default is 0)&lt;br&gt;
55&lt;br&gt;
Number values will be generated randomly What is the Minimum value?(default is 100)&lt;br&gt;
60&lt;br&gt;
What is the filename to store the data in?(default is data.txt, if file exists, data will be concatenated at EOF)&lt;br&gt;
my_random_data.txt&lt;br&gt;
What kind of delimiter would you like, comma or newline?(default is newline)&lt;br&gt;
comma&lt;br&gt;
Add tab-delimited ids, yes or no?(default is no)&lt;br&gt;
no&lt;br&gt;
Generating 1000 numbers between 55 and 60...&lt;br&gt;
File: my_random_data.txt saved successfully!&lt;br&gt;
&lt;/div&gt;

I just thought i'd share, as this may be useful for people that need any amount of random data to use. </description>
      <pubDate>Wed, 28 Oct 2009 17:54:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/22</link>
      <guid>22</guid>
    </item>
    <item>
      <title>Converting a String to a Class in Ruby</title>
      <description>&lt;p&gt;In Ruby, you can easily convert a string, or any kind of text, into a Class. Here's a quick example: &lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
class_name = &quot;new_class&quot; # set string with name of class, will camelize to NewClass 
new_object = class_name.camelize.constantize.new # call NewClass.new
&lt;/pre&gt;

</description>
      <pubDate>Tue, 27 Oct 2009 19:39:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/23</link>
      <guid>23</guid>
    </item>
    <item>
      <title>Opal Released!</title>
      <description>&lt;div style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;http://hulihanapplications.com/images/logos/apps/opal_small.png&quot; alt=&quot;Opal Released!&quot; title=&quot;Opal Released!&quot;/&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;h3&gt;Opal Has been Released today!&lt;/h3&gt;Opal is a powerful Item Management Application built in Ruby on Rails. It allows you to list any kind of item, from houses to video games to hotdog vendors. When you install Opal, you tell it the name of the items you&amp;#39;re going to be listing(example: houses), and that&amp;#39;s it! After that, you can create any number of items and show them off using different Item Objects. Try out the demo, or download it for free here:&lt;p&gt;&lt;font color=&quot;#808080&quot;&gt;&lt;a href=&quot;http://www.hulihanapplications.com/projects/opal&quot; target=&quot;_blank&quot; title=&quot;Opal Download&quot;&gt;http://www.hulihanapplications.com/projects/opal&lt;/a&gt;&lt;/font&gt; &lt;/p&gt; &lt;/div&gt;</description>
      <pubDate>Tue, 14 Jul 2009 19:43:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/21</link>
      <guid>21</guid>
    </item>
    <item>
      <title>Rails Colored Number Comparison Helper</title>
      <description>Here's a quick function that we use in some of our Ruby on Rails applications to print out a colored number that indicates a comparison with another number. Basically, you pass in a value(the number you're comparing) and a maximum(the number you're comparing &lt;b&gt;value&lt;/b&gt; against), and it will return a color that indicates its amount in comparison to the maximum. We use this to compare quantities in inventory systems, file comparison percentages, and other fun stuff. 
&lt;br&gt;&lt;br&gt;
Here's the code, all you have to do is place it in app/helpers/application_helper.rb
&lt;br&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
 def colored_comparison(value = 0, maximum = 0, options = {:direction =&gt; &quot;down&quot;, :display =&gt; &quot;plain&quot;}) # compare value against another value(maximum), print a pretty colored number comparison(red = bad, green = good) signifying comparison
   colors = {:good =&gt; &quot;green&quot;, :middle =&gt; &quot;orange&quot;, :bad =&gt; &quot;red&quot;, :none =&gt; &quot;black&quot;} # color hash
  
   color_key = &quot;none&quot;.to_sym # set default as &quot;none&quot;...see color key below
   if options[:direction] == &quot;down&quot; # compare from maximum down to 0...70/100 -&gt; good, 10/100 -&gt; bad
       if value.to_i &gt;= (maximum.to_i * 0.8) # above half max 
        color_key = &quot;good&quot; # set as good 
       elsif (value.to_i &lt;=  (maximum.to_i * 0.8)) &amp;&amp; value.to_i &gt;= (maximum.to_i * 0.5) # between 50% and 20%
        color_key = &quot;middle&quot; # set as middle
       elsif (value.to_i &lt;=  (maximum.to_i * 0.5)) &amp;&amp; value.to_i &gt;= 0  # less than 20%
        color_key = &quot;bad&quot; # set as good 
       else 
        color_key = &quot;none&quot; # set as none
       end 
    elsif options[:direction] == &quot;up&quot; # compare from 0 up to maximum...70/100 -&gt; bad, 10/100 -&gt; good
       if value.to_i &lt;= (maximum.to_i * 0.2) # below half 
        color_key = &quot;good&quot; # set as good 
       elsif (value.to_i &gt;=  (maximum.to_i * 0.2)) &amp;&amp; value.to_i &lt;= (maximum.to_i * 0.5) # between 50% and 70%
        color_key = &quot;middle&quot; # set as middle
       elsif (value.to_i &gt;= (maximum.to_i * 0.5)) &amp;&amp; (value.to_i &lt;=  maximum.to_i)  # between 70% and 100%
        color_key = &quot;bad&quot; # set as good 
       else 
        color_key = &quot;none&quot; # set as none
       end 
    end 

    if options[:display] == &quot;plain&quot; # return plain colored value, ie: 5
      message = &quot;&lt;font color=\&quot;#{colors[color_key.to_sym]}\&quot;&gt;#{value}&lt;/font&gt;&quot;
    elsif options[:display] == &quot;fraction&quot; # return colored fraction, ie: 5/100 
      message = &quot;&lt;font color=\&quot;#{colors[color_key.to_sym]}\&quot;&gt;#{value}&lt;/font&gt;/#{maximum}&quot;
    else 
      message = &quot;There was a problem! Please check the options you passed in.&quot;
    end 

    return message
  end
&lt;/pre&gt;

Then you can call it anywhere in your views like this:
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
	&lt;%= colored_comparison(10, 100) %&gt; Items Remaining
&lt;/pre&gt;

This should return:&lt;br&gt;
&lt;div class=&quot;code_block&quot;&gt;
&lt;font color=&quot;red&quot;&gt;10&lt;/font&gt; Items Remaining
&lt;/div&gt;


By default, the function assumes that if the value you're comparing is really low(counting in a downward direction), this is a bad thing. Sometimes this isn't a bad thing(If you're counting down to something or trying to get rid of t-shirts, etc.), so you can reverse the direction, by passing in the &lt;b&gt;:direction&lt;/b&gt; option.
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
	&lt;%= colored_comparison(10, 100, options = {:direction =&gt; &quot;up&quot;, :display =&gt; &quot;plain&quot;}) %&gt; Items Remaining
&lt;/pre&gt;
This should return:&lt;br&gt;
&lt;div class=&quot;code_block&quot;&gt;
&lt;font color=&quot;green&quot;&gt;10&lt;/font&gt; Items Remaining
&lt;/div&gt;
You can also set the :display option to return a fraction-looking amount that prints out the number you're comparing against. Here's an example:
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
	&lt;%= colored_comparison(10, 100, options = {:direction =&gt; &quot;up&quot;, :display =&gt; &quot;fraction&quot;}) %&gt; Items Remaining
&lt;/pre&gt;

This should return:&lt;br&gt;
&lt;div class=&quot;code_block&quot;&gt;
&lt;font color=&quot;green&quot;&gt;10&lt;/font&gt;/100 Items Remaining
&lt;/div&gt;

You can change the amounts that are being compared easily(see the function above). It should be pretty straightforward, I just thought I'd share. Post a comment if you have any questions! 

</description>
      <pubDate>Mon, 15 Jun 2009 17:24:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/20</link>
      <guid>20</guid>
    </item>
    <item>
      <title>Check HTTP Response Codes with Ruby</title>
      <description>Checking HTTP Response codes in Ruby is easy to do, and very useful. A normal, working webpage will usually return a 200 response code, which means everything's okay. We all know about 404s(file not found). Also, 500 errors are pretty prevalent, they usually tell you if something strange or buggy is going with the code of a dynamic website or script. Most rails applications throw a 500 Error when they're not working.&lt;br&gt;&lt;br&gt; Using Ruby's Net::HTTP library, you can check these HTTP response codes to see if one of your websites are down, or if one of your ruby on rails applications are acting insane. I like to use these with lists of domains that I monitor for downtime or status. Here's an easy way to do it in ruby:

&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
require &quot;net/http&quot; 
@uri = &quot;http://www.hulihanapplications.com&quot;
@request = Net::HTTP.get_response(URI.parse(@uri))  # returns an Net::HTTPResponse Object
puts &quot;Code: #{@request.code} Message: #{@request.message}&quot; # print the HTTP Response code and Message
&lt;/pre&gt;

This should return:&lt;br&gt;
&lt;div class=&quot;code_block&quot;&gt;
Code: 200 Message: OK
&lt;/div&gt;

&lt;h3&gt;Integrate this into your Rails Application&lt;/h3&gt;
You can also work this into a ruby on rails application, as a view helper, to make it look pretty and color coded, just add this to app/helpers/application_helper.rb:
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
module ApplicationHelper
  require &quot;net/http&quot;
  def print_response(url) # print out HTTP response code and message
	 @req = Net::HTTP.get_response(URI.parse(url)) 
	 color = &quot;black&quot;
	 color_hash = Hash.new # create a hash indexed by response code, contains color
	 # Assign color codes by response code
	 color_hash[&quot;200&quot;] = &quot;green&quot;
	 color_hash[&quot;302&quot;] = &quot;yellow&quot;
	 color_hash[&quot;404&quot;] = &quot;red&quot;
	 color_hash[&quot;500&quot;] = &quot;red&quot;
	 
	 #if @req.code == 200
	 #   color = &quot;green&quot;
	 #end
	 return &quot;&lt;font color=\&quot;#{color_hash[@req.code.to_s]}\&quot;&gt;#{@req.code} #{@req.message}&lt;/font&gt;&quot;
  end
end
&lt;/pre&gt;
&lt;br&gt;

Then you would call this from any view:
&lt;pre name=&quot;code&quot; class=&quot;ruby:nocontrols&quot;&gt;
www.hulihanapplications.com - &lt;%= print_response(&quot;http://www.hulihanapplications.com&quot;) %&gt;
&lt;/pre&gt;

This would end up looking like this:&lt;br&gt;
&lt;div class=&quot;code_block&quot;&gt;
www.hulihanapplications.com - &lt;font color=&quot;green&quot;&gt;200 OK&lt;/font&gt;
&lt;/div&gt;

&lt;br&gt;or, if the site is down&lt;br&gt;
&lt;div class=&quot;code_block&quot;&gt;
www.hulihanapplications.com - &lt;font color=&quot;red&quot;&gt;404 Not Found&lt;/font&gt;
&lt;/div&gt;

That's it! This is a good way to check if a website or domain is down from any script or application.&lt;br&gt;&lt;br&gt;

You can learn more about what attributes a &lt;a href=&quot;http://www.ruby-doc.org/core/classes/Net/HTTPResponse.html&quot;&gt;Net:HTTPResponse&lt;/a&gt; object has 
	&lt;a href=&quot;http://www.ruby-doc.org/core/classes/Net/HTTPResponse.html&quot;&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
You can also read more about the &lt;a href=&quot;http://www.ruby-doc.org/core/classes/Net/HTTP.html&quot;&gt;Ruby Net::HTTP&lt;/a&gt; library 
	&lt;a href=&quot;http://www.ruby-doc.org/core/classes/Net/HTTP.html&quot;&gt;here&lt;/a&gt;.&lt;br&gt;
</description>
      <pubDate>Mon, 25 May 2009 19:35:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/19</link>
      <guid>19</guid>
    </item>
    <item>
      <title>Rails Cache Problems with .htaccess</title>
      <description>Page caching is an important performance tool when it comes to dynamic webpages. Ruby on Rails has some cool page caching options that help store dynamically generated pages 
as flat html files, so as long as a rail pages doesn't change very much, it's a good idea to cache it. This minimizes server load and allows your browser to grab the page very quickly. 
&lt;a href=&quot;http://www.railsenvy.com&quot;&gt;Rails Envy&lt;/a&gt; has a &lt;a href=&quot;http://www.railsenvy.com/2007/2/28/rails-caching-tutorial&quot;&gt;great tutorial&lt;/a&gt; for getting started with page caching. There's even a section that tells you how to store cached files in a custom directory of your choice. Very cool.
&lt;br&gt;&lt;br&gt;
However, I ran into a few snags when implementing it with rails 1.2.6. The pages were getting generated properly in the public/cache folder, but when I went to the page in question, the cached file wasn't 
being served. How cached files are served to a visitor all depends on the webserver that's running. In my case, I'm running rails on Apache, via fastcgi or cgi. This means that there's a file in the public folder, .htaccess, that controls how requests are sent to rails. This is an override file for apache, that lets you customize Apache settings and configuration for a particular folder. There's a section in the .htaccess file that tells apache to look for cached files first, and if none are found, send the HTTP request to rails, through dispatch.fcgi. Here's what that section looks like normally:

&lt;pre name=&quot;code&quot; class=&quot;html:nocontrols&quot;&gt;
	RewriteRule ^$ index.html [QSA]
	RewriteRule ^([^.]+)$ $1.html [QSA]
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
&lt;/pre&gt;
&lt;br&gt;
Now since I'm placing all cached content in the cache folder, the section should be changed to this, right?
&lt;pre name=&quot;code&quot; class=&quot;html:nocontrols&quot;&gt;
	RewriteRule ^$ cache/index.html [QSA]
	RewriteRule ^([^.]+)$ cache/$1.html [QSA]
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
&lt;/pre&gt;
&lt;br&gt;
Wrong! This didn't work for me at all, I even tried using a leading slash, ie: /cache/. Apache refused to look in the cache folder, and cached files still weren't served. After much searching, I finally stumbled upon the correct apache directives for a custom cache directory. Here's what it looks like:
&lt;pre name=&quot;code&quot; class=&quot;html:nocontrols&quot;&gt;
	# This directive will look in public/ for cached files
	RewriteRule ^$ index.html [QSA]
	RewriteRule ^([^.]+)$ $1.html [QSA]
	# This directive will look in public/cache/ for cached files
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule !^cache/(.*) - [C]
	RewriteRule ^(.*)$ cache/$1 [QSA] 
	# If nothing is found, send to rails 
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
&lt;/pre&gt;
&lt;br&gt;Finally, it worked properly. This particular set of directives also will look in just the public directory, so remove the first 3 lines(including the comment) if you don't want this to happen. 
It took me a while to find this fix, so I thought I would share. 
</description>
      <pubDate>Fri, 24 Apr 2009 13:00:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/18</link>
      <guid>18</guid>
    </item>
    <item>
      <title>BXR Released</title>
      <description>&lt;div style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;http://www.hulihanapplications.com/images/logos/apps/bxr_big.png&quot; alt=&quot;BXR&quot; title=&quot;BXR&quot; /&gt;&lt;/div&gt;&amp;nbsp;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Hi Everyone! We released BXR today, a free, open source, file management sytem. It is based off of &lt;a href=&quot;http://boxroom.rubyforge.org/&quot;&gt;Boxroom&lt;/a&gt;, an open source file management project. BXR allows you to create folders, users, and groups, and assign permissions, so you can secure different folder and files. You can also search for files and folders, either by keyword, or by file content. Organization of files is easy! Besides being able to upload files to different folders, you can also add specific tags/labels to each file. &lt;/p&gt;&lt;p&gt;Check out the project page at:&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;http://www.hulihanapplications.com/projects/bxr&quot; target=&quot;_blank&quot;&gt;http://www.hulihanapplications.com/projects/bxr&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Or try out a demo at(username: &lt;strong&gt;admin &lt;/strong&gt;- password: &lt;strong&gt;admin&lt;/strong&gt;): &lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;http://bxr.demos.hulihanapplications.com/&quot; target=&quot;_blank&quot;&gt;http://bxr.demos.hulihanapplications.com/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can also track the development of BXR, if you want to report a bug, suggest new features, and so on, in the &lt;a href=&quot;http://dev.hulihanapplications.com/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Hulihan Applications Software Development System &lt;/strong&gt;&lt;/a&gt;:&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;http://dev.hulihanapplications.com/projects/show/bxr&quot; target=&quot;_blank&quot;&gt;http://dev.hulihanapplications.com/projects/show/bxr&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;</description>
      <pubDate>Thu, 26 Feb 2009 10:43:00 +0000</pubDate>
      <link>http://blog.hulihanapplications.com/browse/view/17</link>
      <guid>17</guid>
    </item>
  </channel>
</rss>
