Upgrading your Authlogic Gem for Rails3

转自 http://iterat.ive.ly/index.php/2010/09/03/upgrading-your-authlogic-gem-for-rails3/

 

If you’re using Authlogic in Rails3 (or if you’re upgrading your existing app from 2.3.8 to Rails3) you really need to be using the rails3 branch of the Authlogic gem. If you’re using Bundler, this is super-easy because you just need to update your Gemfile.
In your Gemfile, update the authlogic line to be:
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
Now you should run $ bundle install to grab the new gem. Then, there are just a few more deprecated things in Rails3 that you’ll need to change in your upgraded app. I’ll try to enumerate here from memory, so please forgive me if I forget something.
First, you need to update your ApplicationController because #requesturi is outdated. Replace it with #fullpath:
def store_location
  session[:return_to] = request.fullpath
end
Second, you need to drop the filter_parameter_logging setting from your ApplicationController because it’s now handled in the new application.rb file. Just remember to add the :password_confirmation field to the default array like so:
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password, :password_confirmation]
Third, if your migration script (or the steps you followed manually) didn’t get rid of the /config/initializers/cookie_verification_secret.rb file, delete it now. Cookie secrets are now handled in the /config/initializers/secret_token.rb file.
Fourth, the f.error_message construct isn’t available anymore in core rails, so you should take this opportunity to create your own better more customizable error messages. If you really really want to keep using f.error_message you can install the dynamic_form plugin, but don’t do that. Railscast.com did a very nice explanation of how to create your own shared _error_messages.html.erb view (along with some other validation-related stuff.)
Finally, you need to make sure your generated pages include the csrf_meta_tag. Check out my previous post if you’re getting an InvalidAuthenticityToken error when you hit the Logout link.
That should be all you need to do to have Authlogic working in Rails3 without deprecated warnings.

 

你可能感兴趣的:(rails3,authlogic)