A few days ago I began setting up a rails app that was in need of some user authentication. A friend of mine recommended looking at @technoweenie‘s restful_authentication plugin and I already had messed around with heroku’s hosting service. Now it was time to combine the two.
I initially installed the restful_auth plugin using the ‘git clone’ method and my app worked perfectly fine on my local machine. However, when I uploaded the app to heroku, I was hitting a few errors. The first error was that my app was failing to launch because it could not find a const named ‘User::Authenticated’ … how’s that possible? I installed the plugin , shouldn’t it just know where to look for it? Well it appears that if you use the ‘git clone’ method to install the plugin, it will not work on heroku. You must install the plugin by running ‘script/plugin install git://github.com/technoweenie/restful-authentication.git’. This will put all the pieces in the correct place. ALSO, be sure to change the name of the folder downloaded to ‘restful_authentication’ .. that is … change the hypen to an underscore. Once I changed that, I re-launched my app on heroku using the command ‘heroku restart’, and I hit a (NameError). Seems the ‘script/plugin install’ command didn’t create an file called user_observer.rb that should be placed in the models directory. I’m not sure if this is a bug at this point but this is the workaround I used:
drop a file named user_observer.rb in your /app/models/ directory and put this code in it:
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserMailer.deliver_signup_notification(user) if user.not_using_openid?
end
def after_save(user)
UserMailer.deliver_activation(user) if user.recently_activated? && user.not_using_openid?
end
end
Once I had this file in place, my app launched successfully and now included full user authentication.
YAY!