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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:58:42+00:00 2026-06-14T14:58:42+00:00

I have a form with a create method that inputs data that goes into

  • 0

I have a form with a create method that inputs data that goes into my “users” table and “user_details” table.

When I get redirected after the create method is complete, there is a “delete” query that removes my new record from the “user_details” table.

Why is this delete line happening?

log which shows delete happening

Redirected to http://localhost:3000/home
Completed 302 Found in 518ms


Started GET "/home" for 127.0.0.1 at 2012-11-20 20:32:25 -0600
  Processing by SessionsController#index as HTML
  SQL (0.2ms)  BEGIN
   (0.1ms)  COMMIT
  User Load (0.3ms)  SELECT `users`.* FROM `users` ORDER BY id DESC LIMIT 5
  UserDetails Load (0.6ms)  SELECT `user_details`.* FROM `user_details` WHERE `user_details`.`user_id` = 34 LIMIT 1
  SQL (0.1ms)  BEGIN
  SQL (0.2ms)  DELETE FROM `user_details` WHERE `user_details`.`id` = ?  [["id", 8]]
   (6.0ms)  COMMIT
  UserDetails Load (0.5ms)  SELECT `user_details`.* FROM `user_details` WHERE `user_details`.`user_id` = 1 LIMIT 1
  SQL (0.1ms)  BEGIN
   (0.0ms)  COMMIT
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  CACHE (0.0ms)  SELECT `user_details`.* FROM `user_details` WHERE `user_details`.`user_id` = 1 LIMIT 1
  SQL (0.1ms)  BEGIN
   (0.1ms)  COMMIT
Rendered sessions/index.html.erb within layouts/application (0.2ms)
Completed 200 OK in 235ms (Views: 63.6ms | ActiveRecord: 93.7ms)

User model

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:login]

  # Virtual attribute for authenticating by either username or email
  # This is in addition to a real persisted field like 'username'
  attr_accessor :login

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :login, :home_phone, :cell_phone, :work_phone, :birthday, :home_address, :work_address, :position, :company, :user_details_attributes

  has_one :user_details, :dependent => :destroy
  accepts_nested_attributes_for :user_details
  after_initialize :build_user_details

  # validates email or username when logging in
  def self.find_first_by_auth_conditions(warden_conditions)
    conditions = warden_conditions.dup
    if login = conditions.delete(:login)
      where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
    else
      where(conditions).first
    end
  end

end

User_details model

class UserDetails < ActiveRecord::Base
  belongs_to :user

  attr_accessible :first_name, :last_name, :home_phone, :cell_phone, :work_phone, :birthday, :home_address, :work_address, :position, :company

  def full_name
    [self.first_name, self.last_name].compact.join(' ')
  end

end

Sessions controller

class SessionsController < ApplicationController
    layout 'application'

    before_filter :authenticate_user!

    def index
        render :layout => 'application'
    end

    def new
        render :layout => 'login'
    end
end

application controller

class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :instantiate_user, :instantiate_message, :recent_users, :authenticate_user!

    def instantiate_user
        @user = User.new
    end

    def instantiate_message
        @message = Message.new
    end

    def recent_users
        @recents = User.last(5).reverse
    end
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-06-14T14:58:43+00:00Added an answer on June 14, 2026 at 2:58 pm

    Commenting out after_initialize :build_user_details from the user model solved my issue. I had added it because i was having this issue Rails how to get associated model attributes, but that issue is solved now too.

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

Sidebar

Related Questions

I have an admin form that lets users create entities that require an image.
I have the following form setup: <html> <head></head> <body> <form method=post enctype=multipart/form-data action=FileUpload> <table>
I have a simple form in my MVC3 site that allows users to create
I have a form. In that form I create an instance of a class
I have a form on a page that a user can use to create
I have a web form that uses if statements to create a string of
I have a form that submits data to a database in a CodeIgniter app
I'm trying to create a simple crud form to insert data into a database
I have a form that gets populated with data from the database. Before is
I have an html table that pulls data from a DB. It has an

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.