Perfect Circle

Yup, back on WordPress.

Radiant is an awesome CMS, but it’s still at heart a CMS. Mephisto is just undermaintained and hasn’t got any buzz around it, but WordPress still manages to impress me as a piece of software. I’m willing to overlook that dark, PHP-based heart nestling under the pretty face.

I’m also intending to start blogging more often, and finally might get some purpose to these posts. I’ve got Twitter for my outpourings now, so hopefully I’ll continue the trend I started with more Rails, EVE and other dedicated posts on those topics rather than my usual rambling post about everything. Oops.

My laptop is very, very sorted at this point, and I plan to dedicate a few posts detailing my setup and steps to reproduce it. I’ve got everything from Compiz to monitor-mode WLAN, 2-factor authentication using one-time-pads on a USB stick to Processing running well. Not bad for a £300 bit of kit, and certainly above my expectations as to what I could achieve with it. I’ve been playing around a lot with wireless gear too, and plan to have some serious playtime with WPA2 at some point. Certainly a moderately serious aerial project is on the cards for the EeePC!

Selectively modifying attr_accessible

I came across the need to have a user list with checkboxes for ‘admin’ and ‘fleet_commander’ to allow them to be set. Which works great- until you realise that your user model is protected from forms setting those fields!

This was using the ‘Toggle Attributes with Ajax’ recipe from ‘Advanced Rails Recipes’- an excellent book, and one I’d recommend.

Essentially, I had a remote update function using AJAX, which sent a user params hash with the appropriate value set. However, to let the form update the model, I had to use some class_eval magic:

def update
  1.     if current_user.admin?
  2.       User.class_eval('attr_accessible (usual stuff), :admin, :fleet_commander')
  3.     end
  4.     # continue onwards with updating using update_attributes
  5.   end

This temporarily adds the :admin and :fleet_commander attributes to the list of accessible attributes by calling attr_accessible in the context of the User class. Hope this helps someone in the same scenario!