Wednesday 18 August 2010

devise gem provides powerful rails authentication out of the box

I decided that it was time to switch over to authlogic now that I'm a bit more comfortable with ruby and rails, but I couldn't get past an annoying bug where my User.password virtual attribute couldn't be found, despite ensuring that I had the spelling correct for the authlogic "magic" column names, and confirming over and over that I defined attr_accessible :password

Then I stumbled upon a relatively new gem called devise, which comes with modules to satisfy all common project requirements such as automatic account locking, session timeouts, forgotten passwords and more.

After struggling with authlogic for an entire day, it was nice to have devise up and running in a matter of minutes, and see all the aforementioned functionality working out of the box.

One thing that I haven't been able to find online is a convenient reference of the attributes and methods that devise adds to your user model, so I compiled a crude one. It is not categorized by module, but it should be pretty evident by the names:

devise attributes:

confirmation_sent_at
confirmed_at
current_sign_in_ip
failed_attempts
last_sign_in_at
last_sign_in_ip
locked_at
locked_out_at
sign_in_count
unlock_token

devise methods:

access_locked?
active?
confirmation_required?
confirmed?
if_access_locked
lock!
lock_access!
locking_enabled?
lock_expired?
resend_unlock_token
reset_password!
send_reset_password_instructions
timedout?
unless_confirmed
unlock_access!

Wednesday 7 April 2010

github project howto: fork, clone, modify, request merge

I use the searchlogic gem by binarylogic for report search filters and it works great, but unfortunately it doesn't support the rails datetime_select helpers. The issue has existed on github for many months, and one user even offered a nice gist to fix the problem. Many months later and it still has not found its way into searchlogic master. So I figured its time to give back to the open source community by making it as easy as possible for Ben to incorporate the fix.

1. Fork the project on github http://help.github.com/forking/

2. Clone your fork.
2.1 If you have never done this before, you'll have to upload a private ssh key to github first. See http://help.github.com/mac-key-setup/
2.2 Then you can clone your newly-forked version of the project:

git clone git@github.com:philrosenstein/searchlogic.git

3. Run the tests. In my case I provided a relative path to spec in my rails project.

../path/to/script/spec ./spec/search_spec.rb -c

4. Make the changes locally. Using your favorite editor of course.

5. Run the tests again to make sure you haven't broken anything. You should also add new test cases if you have added functionality.

6. Commit the changes.

7. Request a merge from the project owner. If you are confident in your changes and they will make the project better for others, this is where you give back to the community that your projects have benefited so much from!