I have an app that uses Rolify, Devise, CanCan, and Tabulous.
In my tabulous.rb
file, I want to be able to define the Visibility?
of a tab by calling:
(current_user.has_role? :admin)
So the config.tabs
do will look something like this:
# TAB NAME | DISPLAY TEXT | PATH | VISIBILE? | ENABLED?
[ :admin_tab, 'ADMIN' , ingredients_path , (current_user.has_role? :admin) , true ],
Which works fine for most of the pages EXCEPT for when I go into the /users/sign_in
path; it returns the following error:
NoMethodError in Devise/sessions#new
Showing /Users/[myname]/Projects/[project-name]/app/views/layouts/application.html.haml where line #24 raised:
undefined method `has_role?' for nil:NilClass
And line #24 just points to the =tabs
call within the applications.html
file.
I know the problem is that /users/sign_in
doesn't have access to the .has_role?
function.
How can I make it so that the tabulous.rb
file can use it?