3

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.

2 Answers 2

4

Fix it in your routes

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Nick. I'm new to RoR and still haven't captured the concept of routes.
2

ApplicationController.rb

def after_sign_in_path_for(resource)
    users_dashboard_path
end

Routes.rb

namespace :users do
  get 'dashboard' => 'dashboard#index', as: :dashboard
end

Note: I have created my Dashboard Controller inside Users folder created by Devise. (like this => 'users/dashboard_controller.rb') Hope this working example will help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.