From b8d91cdfb9435e43806c177f44fcc972465b16d1 Mon Sep 17 00:00:00 2001 From: Mark Roghelia Date: Wed, 31 Aug 2011 23:41:17 -0400 Subject: [PATCH] Updated DeviseGenerator to respect singular tables. If ActiveRecord::Base.pluralize_table_names is set to false, the table for AdminUser will be admin_user, but the route generated by Devise will still be admin_users. However, the Active Admin route generation assumed the route name would always be the same as the table name when doing a gsub in the routes file. Since the gsub didn't match the trailing 's' in the route name, you ended up with the following in routes.rb: devise_for :admin_user, ActiveAdmin::Devise.configs This resulted in a NoMethodError because of the leftover 's' on the end of the line: undefined method `configs' for ActiveAdmin::Devise:Module (NoMethodError) Switching from table_name to plural_table_name in the generator ensures it matches the complete route name regardless of the value of ActiveRecord::Base.pluralize_table_names. --- lib/generators/active_admin/devise/devise_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/active_admin/devise/devise_generator.rb b/lib/generators/active_admin/devise/devise_generator.rb index b3c2f814218..3b7daa6a766 100644 --- a/lib/generators/active_admin/devise/devise_generator.rb +++ b/lib/generators/active_admin/devise/devise_generator.rb @@ -31,7 +31,7 @@ def remove_registerable_from_model def set_namespace_for_path routes_file = File.join(destination_root, "config", "routes.rb") - gsub_file routes_file, /devise_for :#{table_name}/, "devise_for :#{table_name}, ActiveAdmin::Devise.config" + gsub_file routes_file, /devise_for :#{plural_table_name}/, "devise_for :#{plural_table_name}, ActiveAdmin::Devise.config" end def add_default_user_to_migration