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

  • Home
  • SEARCH
  • 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 7012487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:15:44+00:00 2026-05-27T22:15:44+00:00

Anytime I create a user and log in this exception is thrown on the

  • 0

Anytime I create a user and log in this exception is thrown on the redirect: Couldn't find User without an ID.

I have a has_many association like so:

class Post < ActiveRecord::Base
has_many :tags
belongs_to :user

attr_accessible :title, :description, :content, :tags_attributes

accepts_nested_attributes_for :tags, allow_destroy: true, reject_if: lambda {|attrs| attrs.all? {|key, value| value.blank?}}

end

followed by:

class User < ActiveRecord::Base

has_many :posts
attr_accessible :codename, :password, :password_confirmation

end

There is a third model ‘Tags’ which has a belongs_to post but that does not appear to be causing the problem. There is also a SessionsController with new,create, and destroy actions (code below).

The find_user method is run only on the new and create actions in the PostsController

before_filter :find_user

def find_user
 @user = User.find(params[:user_id])
end


def new
 @post = @user.posts.build(tags: Tag.new)
  respond_to do |format|
   format.html 
  end
end

def create
 @post = @user.posts.build(params[:post])
 @tags = @post.tags.build(params[:tags])
  respond_to do |format|
  if @post.save
    format.html { redirect_to @post, notice: 'Post was successfully created.' }
  else
    format.html { render action: :new }
  end
 end
end

and the User.authenticate method / SessionsController create action

def self.authenticate(codename, password)
 user = User.find_by_codename(codename)
  unless user && user.authenticate(password)
   raise "You are not who you say you are."
  end
 user
end

def create
 session[:user_id] = User.authenticate(params[:codename], params[:password]).id 
 redirect_to action: session[:intended_action], controller: session[:intended_controller], success: "You're In!"
end
  • 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-27T22:15:45+00:00Added an answer on May 27, 2026 at 10:15 pm

    The problem seems to be easy – you storing id of authenticated User in session object, but trying to fetch user using params[:user_id] instead of session[:user_id]

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

Sidebar

Related Questions

I've been having this problem where anytime I send a 0xA through an RS-232
Question Is there a way to have a method that will always run anytime
I have a site using CF8 and Fusebox 5. Anytime I need to add
I'm trying to create an ASP.NET/C# page that allows the user to edit a
I have an action Create() on my BooksController, where I create a new Book
We have a system that uses sp_getapplock to create an exclusive mutex any time
Assuming I have an user who has an ID and I want to store
i have what seems like a basic scenario for a db trigger in SQL
When a user requests a page, is this when a session is started for
I'm trying to create a Users table that only has OpenId registrations, exactly like

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.