Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Devise - Add action to controller

i got some trouble adding an action in my devise controller. I created a controller named registrations_controller in a folder users/ like this:

class Users::RegistrationsController < Devise::RegistrationsController

And, there is my route file:

root to: 'home#index'

devise_for :users
devise_scope :users do
    get 'users/profil/:id', to: 'users/registrations#profil', as: 'profil'
end

And I see the following error:

Unknown action
Could not find devise mapping for path "/users/profil/1"
This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router.

What's wrong with my code?

like image 712
user2975823 Avatar asked Nov 12 '13 22:11

user2975823


1 Answers

Try the following:

    devise_scope :user do
       get 'users/profil/:id', to: 'users/registrations#profil', as: 'profil'
    end
    devise_for :users, :controllers => {:registrations => "users/registrations"}
    resources :users 

Also you don't need to name the controller Users::RegistrationsController keep it named as RegistrationController keeping the inheritance as you have Devise::RegistrationsController

like image 192
Deej Avatar answered Oct 07 '22 13:10

Deej