How to Make Devise Registrationscontroller to Show Sign_Up Page Only If User Is Already Signed In

How to make devise RegistrationsController to show sign_up page only if user is already signed in?

Devise::RegistrationsController has require_no_authentication before filter by default.

So it's needed to skip it:

class RegistrationsController < Devise::RegistrationsController
skip_before_filter :require_no_authentication
before_filter :authenticate_user!

def new
puts "Method new was called"
super
end

end

Rails Devise: How to access sign up page after signed in?

The way I handled the scenario of being able to create New Users if you are signed in was by generating a User controller and having new and create action methods that would save to the User model. (This was stripped from a current app I'm working on so hopefully I didn't miss 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 page

<%= link_to 'New User', new_user_path %>

Customize Devise redirect if already signed_in user tries to sign up again

The code in the source code that redirects the user is the filter :require_no_authentication. If you overwrite the Devise::SessionsController to skip that filter, you will be able to redirect your user your chosen path.

Like so:

class Users::SessionsController < Devise::SessionsController
# Note that all the other actions are handled by Devise::SessionsController
# (which is in the gem)
skip_filter :require_no_authentication, only: :new
def new
if user_signed_in?
redirect_to dashboard_path
return
end
super
end
end

Devise: How to create a new user being already logged in?

Found.

I have just to removed the registerable module from devise and it works.

Devise before filter that prevents access to new_user_registration_path unless user is signed-in

Create a Controller with class Devise::RegistrationsController heriting. After you can add your filter. You just need define this controller like registration controller

class RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!
end

In your routes.rb

devise_for :users, :controllers => { :registrations => 'registrations'}

After generating devise:views my sign_up page doesnt trigger any action

I found the solution. Apparently it was due to a form-control html tag that i added and that somehow interfered with the devise controller.
Keeping the customization only to a div container-fluid and few essential changes solved the issue. Thanks anyway!

How to redirect user back to login form after signing up with devise?

Check out devise documentation. Assuming, you have the routes setup for devise.

# routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}

# registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController

protected

def after_sign_up_path_for(resource)
new_page_path
end
end


Related Topics



Leave a reply



Submit