Authlogic Help! Registration of a new user at login as a user who is not working

Just like a disclaimer, I am new to rails and programming in general, so I apologize for misunderstanding something obvious.

I have Authlogic with activation and startup. Therefore, for my site, I would like my users to log in to be able to register other users. The new user will select their username and password via activation email, but the existing user must post them by email, location and several other attributes. I want an existing user to do this.

The problem I encountered if I logged in and then try to create a new user, it just tries to update an existing user and does not create a new one. I'm not sure if there is any way to fix this by starting another session of the session? Even if it’s right / possible, I don’t know how to implement it.

I understand that without knowing completely about my application, it can be difficult to answer this, but does it look like this is the right way? Did I miss something?

User 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
+3
source share
2 answers

Could you insert your users and user_session controller code?

Ryan Bates nifty_authentication gem. authologic default restful_authentication

script/generate nifty_authentication --authlogic

.

+1

, , ! !:)

, before_filter: require_no_user , .

? ? post/put?

.

0

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


All Articles