jump to navigation

Passenger with Rails 2.3 application (MissingSourceFile) March 1, 2009

Posted by John Dewey in Apache, New Category, Passenger, WebServers.

I’m such an idiot. I spent the last few days, trying to figure out the following error reported on my Ubuntu 8.10 Passenger install.

Error message:
no such file to load -- application (MissingSourceFile)

Exception class:

I was installing libapache2-mod-passenger_2.0.3 from the apt-get repo, which does not understand the application_controller.rb rename.

2.0.6 mod-passenger has yet to show up in the apt-get repo. You can use these instructions to install the brightbox mod-passenger build.

using geminstaller with vlad the deployer February 28, 2009

Posted by John Dewey in Configuration, Deployment, Example, Rake, Vlad.
1 comment so far

I really really really like vlad the deployer. I recently switched my apps over to geminstaller vs Rails’ config.gem.

This gist adds in geminstaller functionality to vlad’s update task.

ActionMailer Timeouts February 22, 2009

Posted by John Dewey in Code, Monkey Patch, Rails.
add a comment

The following gist contains a monkeypatch allowing configurable timeouts on ActionMailer.  Since ActionMailer is blocking, it is nice to set a reasonable timeout, rather than wrapping each of your ActionMailer calls with a Timeout (alarm).  I actually monkeypatch all of ‘net/smtp’, so just rescue ‘Timeout::Error’ where needed.

chef-solo VPS provisioning February 21, 2009

Posted by John Dewey in Apache, Automation, Chef, Code, Configuration.
add a comment

I probably built a naive chef solo configuration. I also know I could have used one of the many “Ready Stack” solutions VPS providers are creating. However, I like my systems setup a particular way.

Take a peek the configuration is pretty cool. The code is on github.

Ideally chef would have built my system from the ground up, installing ruby, libs, etc… Since I do not control this piece, there are a few prerequisites to setting up chef.

Once complete, drop in your virtualhost, and deploy your code. This is not intended as zero-conf. Merely a standard base configuration for all of my hosts.

icanhasrspec – lolspek sneak peek February 17, 2009

Posted by John Dewey in Example, RSpec.

mah frend reid addd lolspeak 2 rspec. i am bloggin dis as wai 2 persuade him 2 post hims gist. 🙂

updat0rz: teh gist addded – kthxbye

requiring javascript_helper outside rails December 30, 2008

Posted by John Dewey in Code, Example, TestUnit.
add a comment

I wanted to fix the tests for css_browser_selector, when updating it to support a rails 2.2.0 change with concat.

However, I would get the following error.

>> require 'action_view/helpers/javascript_helper'
TypeError: wrong argument type Symbol (expected Proc)

As it turns out you must require ActiveSupport first, since the JavaScriptHelper requires Sym#to_proc.

Also, ActionView::Helpers::JavascriptHelper alias was removed – yay tests!

Am I rspec-tarded? December 29, 2008

Posted by John Dewey in Code, Example, RSpec, Ruby.
1 comment so far

So I want to test the xml declaration and xhtml doctype of my application layout.

I ended up with this pastie.
Does anyone know of a way to accomplish this using rspec‘s have_tag/with_tag? I’m not too fond of the regexp solution in the pastie.

Rails log rotations via rsyslog December 25, 2008

Posted by John Dewey in Code, Configuration, Deployment, Example, Rails.

I have a client that logs their rails logs via syslog, for consumption by pl_analyze. I am not a fan of this, and will probably change it at some point. When using Apache, I’ll typically configure rails to use a rotatelogs pipe.

However, in this case, to avoid changing legacy infrastructure around the logs, I setup rsyslog to do the rotations for me. Hopefully this will be useful to someone else.

This assumes your rails app already logs to syslog.

Added the following to /etc/rsyslog.conf.

Simple_admin met a Pieman November 7, 2008

Posted by dougmcinnes in Code, Plugins & Gems, Rails, Rake, Ruby.
Tags: , , , , ,

Simple_admin is a Ruby on Rails plugin I created at the Los Angeles Times that morphed into a collabrative effort between Dewey, Reid and myself as it traveled between projects and functionality was added.  I’ve just released it to our latimes github account: http://github.com/latimes/simple_admin/tree/master

The basic premise is to give a simple way of managing login usernames and passwords without a database.  The data is stored in a YAML file in the application with the passwords encrypted by String’s crypt() method.

To add users to the file there’s an included rake task: admin:add_user.  The username and password are passed as parameters:

rake admin:add_user username=mrwalrus password=mahbukkit

Rake will append the user to the login.yaml file or create a new one.  The default location for this file is config/admin/login.yml but can be overridden by setting the LOGIN_FILE environment variable in your application.  If you set the LOGIN_FILE differently in your different rails environment files you can have different usernames and passwords for development and production.

There’s also a rake task for adding multiple users at the same time from a text file list, giving them all random passwords.

To get the plugin to actually use Basic HTTP authentication to ask for usernames and passwords add this to your application controller:

include SimpleAdmin
before_filter :check_basic_http_credentials

Like all filters you can add conditions:

before_filter :check_basic_http_credentials, :only => :login

When including SimpleAdmin in your controller you also get access to the authenticate(username, password) method which can be used for custom login pages.  For example:

def login
  if authenticate(params[:username], params[:password])
    session[:admin] = true
    redirect_to main_page

Also included in the plugin is some code for marking different servers as “admin” servers and a way for a rails application to check to see if he’s an admin or not and change its behavior.  We used this on one application running on multiple boxes so we could turn off page caching on the admin-marked boxes so the administration WYSIWYG pages wouldn’t be cached and sent to non-admin users (that would be a big oops).

selectedIndex is your friend on IE6 November 5, 2008

Posted by reidmix in Code, Example, Javascript.
Tags: , , , , , , ,

While working on getting ChainedSelects to work on IE6, I realized there are multiple ways to set an option as selected.  Since ChainedSelects creates all the options for a pre-existing select, I first used the defaultSelected argument passed in the Option constructor:

option = new Option("name", "value", true);

Here, the third argument specifies whether the option is defaultSelected, when the select is first created or the form is reset. This worked fine in Firefox but IE6 blythely ignored it.  So I tried passing a fourth argument that specifies whether the option is currently selected.

option = new Option("name", "value", true, true);

Again, Firefox does the right thing but IE6 gets wacky and incosistently selects the correct option or sometimes does nothing at all.  It seems as if IE6 misses the “selected” message on the event queue, because it works only when i put some alert()s in there.

So I tried another way, by using the selected attribute after creating the option:

option = new Option("name", "value", true, true);
option.selected = true

Again, inconsistent behavior on IE6.  I went to the great oracle and asked google and tried setting the selected attribute to ‘selected’, ‘true’, and ‘yes’ all with no luck.  I wonder if this occurs because the select is pre-existing and is not newly created.  This led me to try out the selectedIndex attribute on the select element.

select = $('myselect')
select.selectedIndex = 3

Bingo!  This works in both Firefox and IE.  The index is 0-based as you would guess (0 is the first option is select.options).