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 7551205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:25:20+00:00 2026-05-30T10:25:20+00:00

In my Rails 3 app, I’m getting redirected to login during my signup process.

  • 0

In my Rails 3 app, I’m getting redirected to login during my signup process. The steps to signup are supposed to be:

  1. User creates User and Profile
  2. Upon saving user, user is logged into the app and redirected to Profiles#edit (/signup/join)
  3. Upon saving profile, user is redirect to Profiles#show (/profiles/:id)

I’m getting redirected to /login after step 1, and I’m seeing a 302 error after the redirect. If I comment out my before_filter :authenticate in profiles_controller.rb and redo the steps above I don’t get redirected out of /signup/join but I get the following error:

NoMethodError in ProfilesController#edit
undefined method `profile' for nil:NilClass

I’m pointed to the first line of my Profiles#edit action:

def edit
  @profile = user.profile
  if @profile.higher_ed?
    higher_ed = HigherEd.find_or_create_by_name(:name => @profile.higher_ed)
  end
  if @profile.employer?
    employer = Employer.find_or_create_by_name(:name => @profile.employer)
  end
  render :layout => "join_form"
end

I’ve been making an attempt to implement CanCan in my app, so I thought that was the cause. However I commented out my entire ability.rb file and the problem persists. I’d obviously like to figure out how to fix this without commenting out the before_filter. So if anyone has an idea I’d greatly appreciate it. Since I’m dealing with CanCan which depends on a current_user, I’ll start with the definition of current_user in my application_controller.rb:

protected
  # Returns the currently logged in user or nil if there isn't one
  def current_user
    return unless session[:user_id]
    @current_user ||= User.find_by_id(session[:user_id])
    @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
  end

  # Make current_user available in templates as a helper
  helper_method :current_user

Here’s my users_controller.rb:

class UsersController < ApplicationController
  before_filter :authenticate, :only => [:edit, :update, :index]
  layout "application"

  def new
    @user = User.new
    @user.profile = Profile.new
    if logged_in?
      redirect_to current_user.profile
    end
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      session[:user_id] = @user.id
      redirect_to join_path, :notice => 'User successfully added.'
      UserMailer.registration_confirmation(@user).deliver
    else
      render :action => 'new'
    end
  end

My profiles_controller.rb:

class ProfilesController < ApplicationController
  #before_filter :authenticate, :only => [:edit, :update]
  helper_method :find_or_create_group
  layout "application", :except => [:edit, :show]

  def new
    @profile = Profile.new(params[:profile])
  end

  def create
    @profile = Profile.new(params[:profile])
    if @profile.save
      redirect_to @user.profile, :notice => 'User successfully added.'
    else
      render :new
    end
    if @profile.higher_ed?
      HigherEd.find_or_create_by_name(:name => @profile.higher_ed)
    end
    if @profile.employer?
      Employer.find_or_create_by_name(:name => @profile.employer)
    end
    if @profile.job_title?
      JobTitle.find_or_create_by_name(:name => @profile.job_title)
    end
    if @profile.high_school?
      HighSchool.find_or_create_by_name(:name => @profile.high_school)
    end
  end

  def user
    @user = current_user
  end

  def edit
    @profile = user.profile
    if @profile.higher_ed?
      higher_ed = HigherEd.find_or_create_by_name(:name => @profile.higher_ed)
    end
    if @profile.employer?
      employer = Employer.find_or_create_by_name(:name => @profile.employer)
    end
    render :layout => "join_form"
  end

My sessions_controller.rb:

class SessionsController < ApplicationController  
  def new
  end

  def create
    if user = User.authenticate(params[:email].downcase, params[:password])
      session[:user_id] = user.id
      cookies.permanent[:auth_token] = user.auth_token
      if user.profile.higher_ed?
        redirect_to user.profile, :notice => "Logged in successfully"
      else
        redirect_to join_path, :notice => "Logged in successfully"
      end
    else
      flash.now[:alert] = "Invalid login/password. Try again!"
      render :action => 'new'
    end
  end

  def destroy
    reset_session
    cookies.delete(:auth_token)
    redirect_to root_path, :notice => "You successfully logged out"
  end
end

My ability.rb for CanCan:

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new  guest user

    if user.role? :admin
      can :manage, :all
    else
      can :manage, :all
    end
  end
end

My routes.rb:

match "/signup/join" => "profiles#edit", :as => 'join'
  • 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-05-30T10:25:21+00:00Added an answer on May 30, 2026 at 10:25 am

    I got it working by reworking my current_user logic. It’s now:

    def current_user
      @current_user ||= lookup_user
    end
    
    def lookup_user
      if cookies[:auth_token]
        User.find_by_auth_token!(cookies[:auth_token])
      elsif session[:user_id]
        User.find_by_id(session[:user_id])
      end
    end
    

    That seems to have done the trick.

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

Sidebar

Related Questions

Simple rails app: I have 2 models, user and intro [which is simply a
My Rails app has a User model and an Idea model. Each user can
Our Rails app is using Restful Authentication for user/session management and it seems that
Simple rails app using Postgres DB, getting 'integer out of range' error when trying
My Rails app is getting the history of changes for two models, using the
I am making an rails app and getting a date back from the server
A Rails app I'm working on will receive emails with attachments and then process
I have a Rails app with a user model that contains an admin attribute.
My Rails app creates a handful of very simple landing pages and I'd like
My Rails app runs in a FB canvas. The problem: If the user isn't

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.