Archive for the ‘problem’ Category

h1

I’m in a wiki

June 18, 2009

I’ve set up an instance of Tracks recently on a dremhost account that I have and it was working lovely until I tried to use the stats page. For some reason it was coming up with a 404 error. I did some searching on the Tracks forum page and found that other people were having the same problem. After reading through the thread and noticing that Dreamhost use stats as the link to their hosting statistics, it occured to me that all that was needed was to redirect the stats controller to a different path.

Armed with this knowledge, the first part was easy. Adding a line similar to what Reinier Balt suggested would point the controller somewhere else. I came up with this line:

map.statistics 'statistics', :controller => 'stats', :action => 'index'

I then had to restart passenger to pick up the changes. The recommended way is to create or touch a file called tmp/restart.txt. All well and good except there is no tmp directory in Tracks. So after some searching around, I decided to create one. Then after a quick “touch tmp/restart.txt” I reloaded the Tracks index page. Lo and behold, it worked!

The link to the stats page had changed to point to statistics and the page loaded…mostly.

There are 11 flash graphs on the page and all of them were trying to load from the old stats/ path. I tried editing the _graph partial file to point to a controller called statistics but to no avail. I tried to redirect the stats controller using

map.resources :statistics, :controller => 'stats'

Nothing changed.

I then tried

map.resources :stats, :as => 'statistics'

but nothing changed again.

Then I managed to stumble on the answer after reading Rails Routing from the Outside In

map.connect 'statistics/:action', :controller => 'stats', :action =>':action' 

What this does is take any link with statistics/moo and points it towards the stats controller and uses moo as the action. After restarting one final time, and reloading the page, voila, statistics with graphs.

So to recap, the fix for a 404 on the stats page on Dreamhost is to add

map.statistics 'statistics', :controller => 'stats', :action => 'index'
map.connect 'statistics/:action', :controller => 'stats', :action =>':action' 

before line 70 or so

map.resources :recurring_todos, 

in config/routes.rb

h1

Flash Chart Helper

May 25, 2009

I’ve been using the Flash Chart Helper recently and it’s been working really well once I got a couple of things ironed out with it.

I followed the instructions and copied all the files to the right place. I had the array created and sending what I thought was the correct format of data to be graphed but I was still getting errors. Originally I had this line:

echo $flashChart->begin(array('prototype'=>true));

at the top of my graph. When I removed the option array (because I wasn’t using prototype) it gave me a lovely graph.

Next thing was add labels to the X-axis. My data set was being sent in the following format:

Array (
[0] => Array (
    [day] => Monday
    [hits] => 0 )
[1] => Array (
    [day] => Tuesday
    [hits] => 15 )
[2] => Array (
    [day] => Wednesday
    [hits] => 58 )
[3] => Array (
    [day] => Thursday
    [hits] => 23 )
[4] => Array (
    [day] => Friday
    [hits] => 23 )
[5] => Array (
    [day] => Saturday
    [hits] => 99 )
[6] => Array (
    [day] => Sunday
    [hits] => 34
) )

So I set up

echo $flashChart->setData($logs, '{n}.hits', '{n}.day', 'byDay');
echo $flashChart->axis('x', array('labels' => $logs));

To explain that, $logs is the array of data, {n}.hits is the data to be graphed, {n}.day is the label path, byDay is the name of the graph. The options for the axis are simply the array to pass in to read the labels from.

I then wanted the labels to be vertical so that they wouldn’t overlap. This proved to be a harder thing to fix. In the API on page three of the helper article, it only mentions

axis($axis, $options = array())

I added in the option of

'vertical' => true

but I got an error that the helper couldn’t find the set_vertical() function. After some digging around in the source, I found that the real way to pass label options was as a third variable to the axis function. So I edited my call to read

echo $flashChart->axis('x', array('labels' => $logs), array('vertical' => true);

and lo and behold, vertical labels!

h1

Mod Rewrite on Leopard

December 10, 2007

After upgrading to Leopard, I had a wee problem with trying to run Cake. It turns out that you need to enable AllowOverride.

In the line that follows:

<Directory “/Library/WebServer/Documents”>

Change “AllowOverride None” to “AllowOverride All” and then restart Apache

h1

A nice way to check if there are orphaned entries

September 5, 2007

In a database table that is linked to another, sometimes an entry gets deleted and the children of that entry don’t get deleted along with it. Use this little bit of SQL to check for these entries:
SELECT one.id
FROM one
WHERE one.other_id NOT IN (
SELECT other.id
FROM other);

This can then be modified to delete those entries by changing the SELECT one.id to DELETE, like this:
DELETE
FROM one
WHERE one.other_id NOT IN (
SELECT other.id
FROM other);

h1

Having problems moving from localhost to remote server

June 20, 2007

I have part of my application working nicely now and it mostly does what I want. But that is only on my localhost. When I copy it up to the remote server, most of it runs. It’s only when I try to update the page with an AJAX call that I get:

Not Found

The requested URL was not found on this server.
Apache Server at Port

I know I ran into this problem before, but can I remember how to fix it? Not on your nelly.

Oh well, at least if I get it fixed this time, it will be logged here for me to remember!