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

  1. Rails 3 Autoloading with Namespaced Models

    I’m working through an upgrade from Rails 2.3.8 to Rails 3.1, and a set of name spaced models that I setup are giving errors when I run a certain Rake task that relies on them. I looked into the issue and it appears that I need to learn the way Rails 3 loads models.

    In /config/application.rb I’m using the following line to auto load all models from /app/models and any subdirectories.

    config.autoload_paths += Dir["#{config.root}/app/models/**/"]

    For this to work I found that I needed to understand how Rails 3 interprets the folder and filenames. Some models weren’t even registering as available, so I created folders for each class and put their files under each folder. This seemed to resolve some errors, but then I was receiving errors when I would try to instantiate a new object from one of the defined classes in the Rails console:

  2. Form Fields not Displaying with Formtastic

    The Rails project I’m currently working on uses Formtastic, a Rails form builder plugin. The projects description says “Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.” I wasn’t sure what DSL means, but found in the projects wiki on the About page that it stands for Domain Specific Language.

    So I’m currently upgrading from Rails 2.3.8 to Rails 3.1, and I found that the form fields were not showing for the pages using the Formtastic semantic_form_for code blocks. I updated my own code so that the equal sign is included after the opening Ruby code tag in the views such as:

    <%= semantic_form_for @product do |f| %>

    … instead of …

    <% semantic_form_for @product do |f| %>

  3. Adding Event Listeners to Google-Maps-for-Rails Markers

    I’m currently working on a Ruby on Rails project that was setup under Rails 2, and we’re upgrading it to Rails 3 via a separate branch.

    We were using a gem called Eschaton to provide Google Maps on certain pages of the website, but it appears that Eschaton is abandoned and actually going to be deleted on October 31, 2011. Because of this I forked the project under my own Github account.

    After looking around for a suitable replacement we decided on Google-Maps-for-Rails, version (1.3.0). Previously with Eschaton we had jQuery code associated with event listeners that were triggered when the markers on the map are selected. When selected the items being plotted on the map, which are displayed to the left of the map, were highlighted using CSS after being clicked on, and page also scrolled down to the item selected on the map. To reproduce this we need to tie events to the markers using Google Maps for Rails (gmaps4rails).

  4. Issues with Bluetooth in OS X Lion after Upgrade

    I recently upgraded from OS X Lion (10.7.1) from Snow Leopard so that I could be up-to-date and benefit from any good features. Truthfully I liked the old Expose and Spaces better than this new Mission Control interface for virtual desktops…but oh well it will do.

    After upgrading to Lion the one thing that has been most frustrating is that my Bluetooth headset doesn’t work anymore. It syncs up with my MacBook Pro, but it doesn’t send audio from the mic nor does it playback audio. I’m using a VXI BlueParrott B250-XT.

  5. Redirect_to not working

    I was just working on a Ruby on Rails controller method that receives information from the previous form via HTTP POST. I coded it so that if certain form variables weren’t present it would set a flash message and redirect to the form page. I tried and tried and still the redirect wasn’t working. I reset my web server, and even restarted my computer, but stil this didn’t resolve the issue.

    I then realized that perhaps redirects aren’t possible with HTTP POST’s, only GET requests. I ended up just creating a generic view for displaying errors, and will render that view and then ‘return FALSE’ inside of the if statement when an error is detected.

  6. Advanced Use of Will_Paginate

    I’m building an index of contacts, displayed with paginated links provided by will_paginate.

    The wiki for this plugin advises you on how to do setup your controller method, and what to put in the view to obtain a simple set of links, such as:

    # /app/controllers/contact_controller.rb
    def index
      @contacts = Contact.paginate :page => params[:page], :per_page => 10, :order => 'created_at DESC'

  7. Getting File object for Paperclip Attachment via S3

    I’m working on a project where we are using the Paperclip plugin for Ruby on Rails for file handling and associations with other models.

    I’m working on a CSV import option right now, using this tutorial to help me get a head start on how to break the contents of the file up into rows and columns. I’m not passing the file directly from a form to the controller method, but I’m opening the file that has already been saved after being uploaded via AJAX.

  8. Issues with MacPorts After Upgrading to OS X Lion

    I realized this morning that I was having dependency issues with ImageMagick on my Mac, which I installed using MacPorts. I had recently upgraded to Mac OS X Lion, so it made sense that I needed to update the software to resolve the issues, much like I had when I upgraded to Snow Leopard.

    I found this article that provided steps for migrating MacPorts for Lion, but I kept getting this error when I tried to uninstall all the packages:

    warning: Failed to execute portfile from registry for apache2
    @2.2.17_1+preforkmpm too many nested evaluations (infinite loop?)
    Warning: Failed to execute portfile from registry for apache2
    @2.2.17_1+preforkmpm too many nested evaluations (infinite loop?)
    Warning: Failed to execute portfile from registry for apache2
    @2.2.17_1+preforkmpm too many nested evaluations (infinite loop?)
    Warning: Failed to execute portfile from registry for apache2
    @2.2.17_1+preforkmpm too many nested evaluations (infinite loop?)

  9. Error: 'unintitialized constant MySQL' with Rails 3 on Snow Leopard Mac

    I just installed Rails 3 on my iMac, which is running Snow Leopard. I’m trying to build a web hosting website/billing system/management system. I configured the app to use MySQL in /config/database.yml like so:

      adapter: mysql
      encoding: utf8
      database: hosting_development
      username: root

    I had to do this because I created the Rails app without specifying that I didn’t want sqlite3. I then ran rake db:create and I got this error:

  10. 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.