Reputation: 930
I'm using ActiveAdmin gem. I want to add a logout link for the menu. So in ActiveAdmin's config file I wrote:
config.logout_link_path = :destroy_admin_user_session_path
And in my application_controller.rb
I add a method:
def destroy_admin_user_session_path
session[:current_admin] = nil
return "/"
end
And back to the ActiveAdmin config I add the menu item:
config.namespace :admin do |admin|
admin.build_menu :defaut do |menu|
admin.add_logout_button_to_menu menu, html_options: {target: :blank}
end
end
Then launch my app but when I visit the admin page I got an internal error:
undefined method `destroy_admin_user_session_path' for " <ul class=\"header-item tabs\" id=\"utility_nav\"></ul>\n":ActiveAdmin::Views::TabbedNavigation
It seems that the symbol :destroy_admin_user_session_path
is not send to my ApplicationController
but something displayed as <ul class=\"header-item tabs\" id=\"utility_nav\"></ul>\n
.
Why does this happen and how to fix it?
Upvotes: 0
Views: 676
Reputation: 5712
I suspect (there's not enough code to tell) that what you want is a view helper, not a controller method. This would allow you to use the method in your views, which is likely where the HTML it's reporting as the error source is.
Move your destroy_admin_user_session_path
method to app/helpers/application_helper.rb
and try again.
If you really want to keep your method in the controller, you can alternatively add helper_method :destroy_admin_user_session_path
to the top of the ApplicationController
class, which turns the method into a helper method available across controllers and views.
Upvotes: 2