Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - Devise Error: undefined local variable or method

I have been checking on SO and the googles for a solution, but I can't figure out what I am doing wrong. I am trying to use the after_sign_in_path_for helper from Devise. I have looked at the documentation on this helper here.

But I am getting the following error upon submitting the sign in credentials:

NameError (undefined local variable or method `dashboard_url' for #
<Devise::SessionsController:0x007fcc36079d88>):
app/controllers/application_controller.rb:27:in `after_sign_in_path_for'

Here's what I'm working with:

config/routes.rb

My::Application.routes.draw do
  get "login/index"
  devise_for :users, path_names: {sign_in: "login"} do
    get '/users/sign_out' => 'devise/sessions#destroy'
  end
 get "dashboard/index"
 root :to => "login#index"
 get 'dashboard' => 'dashboard#index', as: :dashboard_url
 get ':controller(/:action(/:id(.:format)))'
end

The path shows up in rake routes as the following:

rake routes

  dashboard_url GET    /dashboard(.:format)                   dashboard#index

Any help would be appreciated! Thank you.

like image 614
Dodinas Avatar asked Jul 09 '26 18:07

Dodinas


1 Answers

Fix it in your routes

get 'dashboard' => 'dashboard#index', as: :dashboard

Rake routes show your routes helpers without _path and _url suffixes appended.

like image 74
Nick Kugaevsky Avatar answered Jul 13 '26 20:07

Nick Kugaevsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!