Reputation: 2100
I have a small problem that I cant track down. Basically I have my application controller and in my application controller I have a method:
def getCategories
@categories = Category.all
end
Nothing special I have a sidebar partial view that I load in to my main layout. This partial is loaded by almost all controllers/actions with few exceptions so to avoid always declaring this method i simply have a before_filter to invoke this method so that @categories
are automatically included in all controllers.
The problem now is when I attempt to login using devise sign in view it tries to redirect me to root
however for some reason the @categories
are not included and in turn throw this exception:
NoMethodError in Devise::Sessions#create
Which is confusing because according to devise documentation if you set root :to => 'home#index'
as in my case after processing user login user should be redirected to root which points to home controller which should due to before_filter
include the @categoires
variable.
What am I doing wrong here ?
Upvotes: 0
Views: 525
Reputation: 427
Maybe you can try adding a new controller "Registrations" and add your method:
class RegistrationsController < Devise::RegistrationsController
def getCategories
@categories = Category.all
end
end
then Modify config/routes.rb to use the new controller
Modify your devise_for line in routes.rb to look like the below.
devise_for :users, :controllers => { :registrations => "registrations" }
replace root :to => 'home#index'
with
devise_scope :user do
match "/", to: "devise/registrations#new", via: 'get'
end
Upvotes: 2