Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:14:04+00:00 2026-06-03T00:14:04+00:00

I guess the title is self explanatory…how do I make only authenticated users to

  • 0

I guess the title is self explanatory…how do I make only authenticated users to create a user with devise?
when I try to add a new one (when authenticated), devise says that I’m alreade authenticated
any workaround for this?
thanks a lot

edit: as requested, my code

user form

<% if @user == current_user %>
<i class="icon-info-sign"> </i><i>Após alterar seus dados, você terá de fazer login novamente</i>
<% end %>

<%= form_for(@user, :html => { :class => "well form-horizontal"}) do |f| %>
  <% if @user.errors.any? %>
    <div class="alert alert-error">
      <h2><%= pluralize(@user.errors.count, "erro") %> 
        <% if @user.errors.count == 1 %> impede 
          <% else %>
            impedem
        <% end %>
      a continuação:</h2>

      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>


<label>Nome</label><%= f.text_field :nome %>
<label>E-mail</label><%= f.email_field :email %>

<% if @user == current_user or @user.created_at == nil%>
  <label>Senha</label><%= f.password_field :password %>
<% end %>

<div>
<br />
<button class="btn" type="submit">
    Salvar alterações
</button>

</div>

<% end %>

part of users controller

before_filter :authenticate_user!
  def index
    @users = User.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @users }
    end
  end

  # GET /users/1
  # GET /users/1.json
  def show
    @user = User.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @user }
    end
  end

  # GET /users/new
  # GET /users/new.json
  def new
    @user = User.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @user }
    end
  end

  # GET /users/1/edit
  def edit
    @user = User.find(params[:id])
  end

  # POST /users
  # POST /users.json
  def create
    @user = User.new(params[:user])

    respond_to do |format|
      if @user.save
        format.html { redirect_to @user, notice: 'User was successfully created.' }
        format.json { render json: @user, status: :created, location: @user }
      else
        format.html { render action: "new" }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /users/1
  # PUT /users/1.json
  def update
    @user = User.find(params[:id])

    respond_to do |format|
      if @user.update_attributes(params[:user])
        format.html { redirect_to @user, notice: 'User was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

application controller

class ApplicationController < ActionController::Base
  protect_from_forgery

  def after_sign_in_path_for(resource)
        return request.env['omniauth.origin'] || stored_location_for(resource) || painel_path
    end
end

part of routes

App::Application.routes.draw do

  resources :acampantes

  devise_for :users, :skip => [:registrations]

  resources :profiles

  resources :eventos do
    resources :acampantes
  end  

  # aqui tem um has_many, mas não precisa de nested routes
  resources :noticias
  resources :users#, :as => "usuarios"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:14:06+00:00Added an answer on June 3, 2026 at 12:14 am

    The ideal way to do it would be to override registrations_controller.rb (as shown here) and skipping the before_filter check for the new and create action. I tried to do it myself, but unfortunately, I couldn’t get it right.

    Another way to do it, which worked for me, would be to create a separate User controller aside from the Registrations controller provided by Devise:

    class UsersController < ApplicationController
      before_filter :authenticate_user!
    
      def new
        @user = User.new
      end
    
      def create
        @user = User.new(params[:user])
        if @user.save
          flash[:success] = "User saved"
          redirect_to @user
        else
          render 'new'
        end
      end
    end
    
    # routes.rb
    ApplicationName::Application.routes.draw do
      devise_for :users
      resources :users, :only => [:new, :create]
    end
    

    Then make a form for the new action:

    # app/views/users/new.html.erb
    <%= form_for(@user) do |f| %>
    
      <div><%= f.label :email %><br />
      <%= f.email_field :email %></div>
    
      <div><%= f.label :password %><br />
      <%= f.password_field :password %></div>
    
      <div><%= f.label :password_confirmation %><br />
      <%= f.password_field :password_confirmation %></div>
    
      <div><%= f.submit "Sign up" %></div>
    <% end %>
    

    The problem with this approach is that the routes provided by Devise for signing-up still exists. A solution for that would be to prevent Devise from generating routes involving registration:

    # routes.rb
    devise_for :users, :skip => [:registrations]
    

    This means that you are going to ignore the Registrations module completely and make your own. I got this idea from the Bare-bone, stripped-down Devise tutorial. Take note that you should make the controller actions and views to replace the ones provided by the registrations module of Devise. This includes new, edit, create, update, and destroy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess that title is self-explanatory. Is there any such effort been made? Some
I guess the title is self-explanatory.
I think the the title is self explanatory. Although I search actually for the
I guess the question title sums it up. Is there a time when it
As you can guess from the title, the outlining with regions finally made me
I guess the title almost says it all. My original url looks like: http://www.something.com/buy/index.php?p=025823
Ok... so i guess the title is a bit confusing. so i will explain:
I guess I don't give title nicely, anyways, I can explain it better here:
I guess the question is in the title: I want to apply a style
So as the title says i want to prevent user from keep submiting $_POST

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.