Authlogic Help! Registering a new user when currently logged-in as a user not working.
        Posted  
        
            by looloobs
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by looloobs
        
        
        
        Published on 2010-02-05T06:02:10Z
        Indexed on 
            2010/04/01
            22:03 UTC
        
        
        Read the original article
        Hit count: 266
        
ruby-on-rails
|authlogic
Hi Just as a disclaimer I am new to rails and programming in general so apologize for misunderstanding something obvious.
I have Authlogic with activation up and running. So for my site I would like my users who are logged in to be able to register other users. The new user would pick their login and password through the activation email, but the existing user needs to put them in by email, position and a couple other attributes. I want that to be done by the existing user.
The problem I am running into, if I am logged in and then try and create a new user it just tries to update the existing user and doesn't create a new one. I am not sure if there is some way to fix this by having another session start??? If that is even right/possible I wouldn't know how to go about implementing it.
I realize without knowing fully about my application it may be difficult to answer this, but does this even sound like the right way to go about this? Am I missing something here?
Users Controller:
class UsersController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => [:show, :edit, :update]
def new
  @user = User.new
end
def create
   @user = User.new
 if @user.signup!(params)
   @user.deliver_activation_instructions!
   flash[:notice] = "Your account has been created. Please check your e-mail for your account activation instructions!"
   redirect_to profile_url
 else
   render :action => :new
 end
end
def show
  @user = @current_user
end
def edit
 @user = @current_user
end
def update
  @user = @current_user # makes our views "cleaner" and more consistent
  if @user.update_attributes(params[:user])
    flash[:notice] = "Account updated!"
    redirect_to profile_url
   else
   render :action => :edit
   end
 end
end
My User_Session Controller:
 class UserSessionsController < ApplicationController
   before_filter :require_no_user, :only => [:new, :create]
   before_filter :require_user, :only => :destroy
def new
  @user_session = UserSession.new
end
def create
  @user_session = UserSession.new(params[:user_session])
    if @user_session.save
    flash[:notice] = "Login successful!"
      if @user_session.user.position == 'Battalion Commander' : redirect_to battalion_path(@user_session.user.battalion_id)
      else
      end
    else
  render :action => :new
  end
end
 def destroy
  current_user_session.destroy
  flash[:notice] = "Logout successful!"
  redirect_back_or_default new_user_session_url
 end
end
© Stack Overflow or respective owner