Rails Devise: How to access the registration page after logging in?

I am new to rails and I use the “reinvent” gem for authentication purposes.

First I add a new user through the default login page (e.g. / users / sign_up)

Then I made the "sign_up" page accessible only to signed_in users, following the instructions from

Think of a filter that denies access to "new_user_registration_path" if the user is not logged in

Now, after logging in, when I try to open the registration page, it always directs me to root_path! How can I access the registration page?

My file "roots.rb" looks like this:

Example::Application.routes.draw do devise_for :users, :controllers => { :registrations => 'registrations'} resources :companies resources :orders resources :customers root :to => "welcome#index" end 

Thanks everyone!

+4
source share
3 answers

How I handled the scenario of creating new users, if you logged in, a user controller was created and a new one was created and created action methods that would be stored in the User model. (This was shot from the current application I'm working on, hope I haven't missed anything)

user_controller.rb

 def new @user = User.new end def create @user = User.new(params[:user]) if @user.save flash[:notice] = "Successfully created User." redirect_to root_path else render :action => 'new' end end 

views / user / new.html.erb

 <%= form_for @user, :url => user_index_path do |f| %> <p><%= f.label :email %> <%= f.text_field :email %></p> <p><%= f.label :password %> <%= f.password_field :password %></p> <p><%= f.label :password_confirmation %> <%= f.password_field :password_confirmation %></p> <p><%= f.submit "Save" %></p> <% end %> 

config / routes.rb (Rails 3)

 resources :user, :controller => "user" 

Link to the new user’s page

 <%= link_to 'New User', new_user_path %> 
+1
source

I have another solution. Bitterzoet said

As you can see in the source code, if you switch to sign_up, it executes the function before_filter require_no_authentication, and this redirects to the root path, which you can find here.

You do not need to override register_controller, you can only change your own register_controller, which will echo the original register_controller.

 class Admin::RegistrationsController < Devise::RegistrationsController layout 'admin' prepend_before_filter :require_no_authentication, :only => [] prepend_before_filter :authenticate_scope! end 
+3
source

If you are redirected, it means that you are not authenticated correctly when you go to this page, because this requires a valid user session.

Please also post the registration controller file.

If you are redirected, it means that you are not authenticated correctly when you go to this page, because this requires a valid user session.

Please also post the registration controller file.

Addition:

As you can see in devize source , if you go to sign_up, it executes the function before_filter require_no_authentication , and this redirects to the root path, which you can find here .

I think you will have to explicitly override the registered_controller, which I linked first if you really want to override this behavior :-)

+2
source

Source: https://habr.com/ru/post/1333557/


All Articles