rubycoloredglasses


I'm Jason, a web application developer in East Tennessee.


  1. Installing PHPdoc for Ubuntu for use with Command Line

    I wanted to install PhpDocumentor for use on my server so that I could generate documentation from the command line. I found this article, which instructed me to somehow change the PEAR setting for data_dir. I installed PhpDocumentor in my web root and it just didn’t work and gave me a bunch of errors in the browser.

    I uninstalled the package via PEAR (ala ‘pear uninstall phpdocumentor’ command), then deleted the folder. I just wanted to install it in the proper path so that it’s available from the command line using ‘phpdoc’.

    I downloaded the source of PhpDocumentor directly from SourceForge, and it had phpdoc available in the folder, but I’m not sure which folder to put it in so that it’s in my path for the command line.


  2. Ruby on Rails session - Access from PHP

    If you need to access a Ruby on Rails session from a PHP application running under the same domain, you can do this by splitting the string in the cookie by the ‘–’. Thanks to Frederick Cheung for pointing this out.

    Here is coding I added to my PHP script which was running from a path under the same domain. Unfortunately the data returned is in Marshal format, and there isn’t a Marshal.load function for PHP to get the values easily.

    $raw_session_string = $_COOKIE['_app_session'];
    $data_split = explode ('--' , $raw_session_string);
    $encoded_session = $data_split[0];
    $marshal_data = base64_decode($encoded_session);
    echo "<pre>marshal_data:". print_r($marshal_data,1) ."</pre>\n";
    

  3. Obtaining Request Domain Name for Ruby on Rails

    I’m using Rails 2.3.8. To obtain the domain name for the website being requested (i.e. mysite.com, mysite.net), just reference ‘request.host’.

    ruby@host = request.host
    

    You can only reference request.host in the views, or the controller.


  4. Changing Column Order via ActiveRecord Migration

    Is it possible to change the order of the columns in your MySQL (or other database) table using a migration? Lets see.

    If you check the ActiveRecord::Migration documentation you’ll see there is a method called ‘change_column’ which accepts various options.

    <tt>change_column(table_name, column_name, type, options)</tt>:
    Changes the column to a different type using the same parameters as add_column
    

    As of Rails 2.3.6 this is now available by using the :after option. You’ll have to include the field type, even though you are not modifying the type.

    Example:

    change_column :orders, :tax_rate, :float, :after => :tax_state
    

  5. Rails Performance Statistics

    Again, as I search for things, I stumble onto new tools. I just found out about a tool for monitoring the performance of Java and Ruby applications called New Relic.

    They provide a free service level for Startups and Students even.


  6. RailRoad Gem

    I just discovered that there is a Ruby gem which generates diagrams based on Rails models (ActiveRecord). I ran across this website a while back, but didn’t quite connect the dots. I was just reading an article on placing models into their own namespace, and I realized that the diagram it uses as an example was generated using RailRoad.

    [http://railroad.rubyforge.org/]

    Railroad model diagram


  7. Annotate Models

    There is a rails plugin which adds schema information for the models in comments at the top of your model definition files. It’s really useful. Check out the instructions on installing and using this plugin at:

    [http://pragdave.pragprog.com/pragdave/2006/02/annotate_models.html]


  8. Selenium RC, Firefox 3, and Ubuntu

    Selenium Logo

    I’ve got a system setup which uses Firefox on an Ubuntu machine, with the Selenium RC server (remote control). I had a set of scripts which would run automatically every 15 minutes, which would prompt Firefox to open and go to the site and submit certain forms. This stopped working after I ran an update on some packages in my Ubuntu machine (9.04 Jaunty).

    I was able to resolve this issue by upgrading from Selenium RC 1.0.1 to 1.0.3.


  9. Undefined method 'ref' for ActiveSupport::Dependencies:Module

    After upgrading to Snow Leopard, and trying to run ‘rake db:migrate’, I received this error once. This seems common to others which have upgraded, especially back when Snow Leopard was released in August of 2009:

    rake aborted!
    uninitialized constant MysqlCompat::MysqlRes
    (See full trace by running task with --trace)
    

  10. Setting up Deployment for Rails using Capistrano, Apache with Passenger and Git

    I don’t have time right now to learn how to setup Capistrano. I just want a recipe that works and does the job. Here are my notes.

    1. First install the Capistrano gem
    sudo gem install capistrano
    
    1. Next you need to go into the directory of your Ruby on Rails application and capify it:
    capify .