lördag, juli 22, 2006

InPlaceEditor with Autocompletion.

Since the AJAX controls in Rails are so neat, and the InPlaceEditor is probably the neatest since it's so easy and useful, I immediately decided to start fixing one small feature I needed/wanted very much. That is, autocompletion on InPlaceEditor-fields. So, I've created a plugin that does this. It was actually much easier than I thought, since the prototype JavaScript library makes JavaScript almost pain-less to work with. Not quite nice, but not bad either.

Anyway, it's dead simple to use, do it like you've done it with InPlaceEditor and you'll be find. More information can be found here (I've finally convinced my employer to host a place where we can release open source, so it can be seen that KI actually supports open source). The Subversion path is: http://svn.ki.se/rails/plugins/in_place_completer.

Much joy!

söndag, juli 16, 2006

CAS Rails filter

Yesterday I released a Rails filter for doing authentication with CAS. This is really neat, but it's the Rails plugins that make it so neat, since you just have to install the plugin, add three configuration parameters and everything will just work out of the box with all your controllers protected by authentication.

During development it's often practical to not do real authentication, but rather just get a username back as if you'd actually been authenticated already. This can be easily accomplished in three ways with the filter, by a configuration options:

CAS::Filter.fake = "testuid"

which returns the string provided as a username

CAS::Filter.fake = :param

which takes the value of params[:username] and returns this as the authenticated user, and lastly

CAS::Filter.fake = lambda { |controller| ['testuser1','testuser2','testuser3'][rand(3)] }

which invokes the proc every time the filter is called, and uses the string returned as username.

Anyway, authentication is just one of those things that you don't want to think about. It should just be there. And now it is:

script/plugin install http://svn.ki.se/rails/plugins/cas_auth

Enjoy.

Rails and plugin irritation.

I've just started work on a medium sized Rails-application (100-200 hours), and about the first thing I wanted to do was to add my CAS filter (see next posting) to the system. Now, what I'd really like is to be able to set the filter to fake authentication while doing development on my box but going to real authentication when in production. I first tried using $RAILS_ROOT/config/environments/development.rb to set this option, but this doesn't work. Plugins are loaded really late in the startup sequence so my best choice is to add

load "plugin/#{ENV['RAILS_ENV'].rb" if File.exist?("plugin/#{ENV['RAILS_ENV'].rb")

at the end of environment.rb and add my specific configuration to $RAiLS_ROOT/plugin/development.rb

This works, of course, but it is something that I'd thought would already be part of the startup process. Oh well, you can't have everything.