Thursday, December 6, 2007

Ignoring .svn directories with emacs' eshell grep

I'm an emacs user. In the morning I fire up emacs and right away open up an eshell buffer. I prefer the eshell (M-x eshell) over the normal shell buffer due to its little perks like:

dylan:~/one/two/three/four/five$ cd .....


cd ... = cd ../..
cd .... = cd ../../..

It's the little things :).

Also, I like how when I'm in an eshell buffer and run grep, it opens the results in a new buffer and I can continue with whatever I'm doing.

One thing that has been annoying me for a while, however, was that when I ran grep -r in an eshell buffer it would also search through .svn directories, giving me a lot of crud in my results. In a normal bash shell I got around this by adding this line to my ~/.bash_aliases file:

alias grep="grep --exclude=\*.svn\*"

But that didn't work in eshell, since it's not really a bash shell. Luckily, after looking around a little, I found instructions on how to do aliases in eshell. I added a file called ~/.eshell/alias with the following contents:

alias grep grep --exclude=\*.svn\* $*

After killing and reopening my eshell, all is good! No more .svn directories in my greps. You'll notice that the syntax for the aliasing in eshell is similar, but not equal to the bash syntax. It seems you don't need the '=' or the quotes, and also you need to explicitly reference the args with the '$*'.

Thursday, November 29, 2007

Authorization plugin + restful_authentication + rails 1.2.5 = no worky

In a recent application with rails 1.2.5, I started to set up user authentication and authorization using Restful Authentication and the Authorization plugins.

When I added 'acts_as_authenticated_user' to the user.rb model generated by Restful Authentication, the generated specs for Restful Auth started failing with things like this:

NoMethodError in 'User should create user'
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
spec/models/user_spec.rb:99:in `create_user'

After a little investigation, I discovered at some point since the last time I had used these two plugins together, rails started to not like using attr_accessible and attr_protected in the same ActiveRecord class. This was the issue, as Restful Auth was declaring attr_accessible in the user model and Authorization was declaring attr_protected in lib/publishare/object_roles_table.rb line 15.

Commenting out the attr_protected :role_ids in the acts_as_authenticated_user method in object_roles_table.rb fixed the problem.