Cannot override after_inactive_sign_up_path_for on Devise RegistrationsController - ruby-on-rails

I am using Devise with Invitable and Confirmable.
When signin up, I would like to redirect the user to a confirm page, instead of showing the flash message.
I have in my route.rb setup the following:
devise_for :users, controllers: {
:confirmations => 'confirmations',
:registrations => 'registrations'
}
And my RegistrationsController (/app/controllers/registrations_controller.rb) is:
class RegistrationsController < Devise::RegistrationsController
protected
def after_inactive_sign_up_path_for(resource)
"http://google.com"
end
end
But no matter what I try, after_inactive_sign_up_path_for is not being called, and it just continues with the flash message.

Change this
:registrations => 'registrations'
to
:registrations => "users/registrations"
Also, you are overriding the inactive signup, if you want to redirect after a successful signup then you should override def after_sign_up_path_for(resource)

Related

Devise users create other users while logged in

In devise I'm trying to make it so that a Logged in user can create a new user via the Devise signup form.
Currently I've tried overriding the controller but it keeps redirecting me back to the root page due to me being logged in.
registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
skip_before_action :require_no_authentication, only: [:new, :create, :cancel]
protected
def create
User.create!({:email => params[:email], :roles => [''], :password => params[:password], :password_confirmation => params[:password_confirmation] })
end
def sign_up(resource_name, resource)
end
end
routes.rb
devise_for :users, controllers: { registrations: "registrations" }, skip: [:sessions]
Am I missing something obvious, because I assumed the code below would allow it so I could view the form when I'm logged in?
skip_before_action :require_no_authentication, only: [:new, :create, :cancel]
Solution:
I was being too specific in my signup route it was set as devise/registration#new instead of registrations#new
If anyone reading this in future gets stuck, let me know and i'll try my best to help! :)

Unknown action The action 'linkedin' could not be found for Devise::OmniauthCallbacksController

I'm trying to implement Open Authorization within my Rails app so that users can log in with their LinkedIn accounts. When I click on a link to go to the LinkedIn authorization page, and then confirm my LinkedIn credentials, I get an error within my app:
Unknown action
The action 'linkedin' could not be found for Devise::OmniauthCallbacksController
I'm almost positive the issues lies within my routes file. Many tutorials call for the following line to be added:
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }
However, I already have this line here for custom Devise logins:
devise_for :users, :controllers => { :registrations => "registrations" }
I tried switching them but that didn't work (as I expected). Is there a way to combine the two statements?
Thanks!
Issue with omniauth_callbacks_controller:
The action 'linkedin' could not be found for OmniauthCallbacksController
class OmniauthCallbacksController < ApplicationController
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
auth = env["omniauth.auth"]
#user = User.connect_to_linkedin(request.env["omniauth.auth"],current_user)
if #user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success"
sign_in_and_redirect #user, :event => :authentication
else
session["devise.linkedin_uid"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
end
Use
devise_for :users, :controllers => { :registrations => "registrations", :omniauth_callbacks => "omniauth_callbacks"}
This means that you are customizing Devise's RegistrationsController and OmniauthCallbacksController.
For example:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
...
end
And
class RegistrationsController < Devise::RegistrationsController
...
end

Sharing RegistrationController for two devise models

I have two devise models, Individual and Group. I'm trying to share similar behavior for Registrations/Confirmations (send users to a page that informs them that an email has been sent, or send them to the edit page after confirmation, etc.)
My issue is that this works for Individuals, only. It has yet to work for Groups.
config/outes.rb:
devise_for :individuals, :controllers => {:confirmations => "Confirmation", :registrations => "Registrations"}
devise_for :groups, :controllers => {:confirmations => "Confirmation", :registrations => "Registrations"}
app/controllers/registrations_controller.rb:
class RegistrationsController < Devise::RegistrationsController
def after_inactive_sign_up_path_for(item)
"/post_sign_up?email=#{item.email}"
end
end
app/controllers/confirmation_controller.rb:
class ConfirmationController < Devise::ConfirmationsController
def after_confirmation_path_for(name, resource)
case resource.class
when Individual then edit_individual_path resource
when Group then edit_group_path resource
else super name, resource
end
end
end
The above code works for individuals, only. Can't figure out why though.
I was focused so heavily on the provided lines in routes.rb, I failed to notice another "devise_for :groups" at the top of the file. Apparently devise will override previous values in this case. Stupid mistake.
for scale & no errors - better to devide.
admin_registration_controller.rb:
class AdminRegistrationsController < Devise::RegistrationsController
end
user_registration_controller.rb:
class UserRegistrationsController < Devise::RegistrationsController
end
routes:
devise_for :admins, controllers: { registrations: 'admin_registrations' }
devise_for :users, controllers: { registrations: 'user_registrations' }

Cannot override Devise passwords controller

I need my Rails app to redirect to the home page after I submit the email to send me reset password instructions. Devise, by default renders the sign in form after entering the email.
So I am trying to override the Devise::PasswordsController and change its redirect_to, but no success. In fact, I don't think Rails is even taking in my class. It could be a very stupid mistake but I have been at it for half a day with no success.
I took the idea to override the passwords controller from here.
Here's my controller:
class PasswordsController < Devise::PasswordsController
protected
def after_sending_reset_password_instructions_path_for(resource_name)
root_url
end
end
Routes.rb:
devise_for :users, :controllers => {:passwords => "passwords"}
devise_for :users, :controllers => {:registrations => "registrations"}
devise_for :users, :controllers => {:sessions => "sessions"}
I would like to mention that I have overridden Devise's Registations and Sessions Controllers in the same app, and they seem to work fine.
It should be possible to override the controller with the latest version of Devise (2.1.2).
class PasswordsController < Devise::PasswordsController
def new
super
end
def create
..override method here..
end
end
And in config/routes.rb:
devise_for :users, controllers: { passwords: 'passwords', .. }
You can check with rake routes if Rails uses the derived PasswordsController instead of the original one, the routes should for instance contain passwords#new instead of devise/passwords#new.
I think you forgot to mention your changes in the routes:
devise_for :users, :controllers => {:sessions => "sessions", :passwords => "passwords"}

Devise custom registrations controller error

When I try to create a custom devise controller:
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
# add custom create logic here
end
def update
super
end
end
I get a following error:
Unknown action
AbstractController::ActionNotFound
It is not the problem with routes. I tried to inherit RegistrationsController from ApplicationController and it works fine. As soon as i try to inherit from Devise::RegistrationsController it shows an error. It can't be an action problem to, becuse I tried to create a different action, and I get the same error.
# app/config/routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}
root :to => "registrations#new"
Using Rails 3.0.4
In your routes you have to use devise_scope if you are overriding devise default actions.
devise_for :users, :controllers => {:registrations => "registrations"}
devise_scope :user do
root :to => "registrations#new"
end
For a similar issue please see http://groups.google.com/group/plataformatec-devise/browse_thread/thread/a5beaaf4b1ad343a
Also here are the docs on changing default sign in routes, I know this you are doing registration, but this could be similar: https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes
I used the following code in my project successfully:
app/controllers/users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
end
routes.rb
devise_for :users, :controllers => { :registrations => "users/registrations" }

Resources