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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:33:35+00:00 2026-05-27T03:33:35+00:00

Working a simple custom authentication portion for my Ruby on Rails application. I’m trying

  • 0

Working a simple custom authentication portion for my Ruby on Rails application. I’m trying to make email required when the user registers with the app but when I try the registration process, a record is created in the database but email is set to nil. Here’s some code:

My Model:

class User < ActiveRecord::Base  
 attr_accessor :email, :password, :password_confirmation
 before_save :encrypt

 validates :password,
           :presence => true,
           :confirmation => true
 validates :email,
        :presence => true,
        :uniqueness => true,
        :format => { :with => /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\z$/ }

 def encrypt
   if password.present?
     self.password_salt = BCrypt::Engine.generate_salt
     self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
   end
 end

 def self.authenticate(email, password)
   user = find_by_email(email)
   if user && user.password_hash = BCrypt::Engine.hash_secret(password, user.password_salt)
     user
   else
     nil
   end
 end
end

My Controller:

class UsersController < ApplicationController
  skip_filter :login_required, :only => [:create, :new]

  def new
    @user = User.new
    render :layout => 'unauthenticated'
  end

  def create
    @user = User.new(params[:user])
    @user.last_login = DateTime.now
    @user.is_active = true

    if @user.save
      session[:user_id] = @user.id

      redirect_to root_url
    else
      render :action => :new
    end
  end

end

The View:

<div id="register">
  <%= form_for @user do |f| %>
  <% if @user.errors.any? %>
    <div class="error">
      <ul>
        <% for message in @user.errors.full_messages %>
        <li><%= message %></li>
        <% end %>
      </ul>
    </div>
    <% end %>
    <ul>
      <li>
        <%= f.label :email %>
        <%= f.text_field :email %>
      </li>
      <li>
        <%= f.label :password %>
        <%= f.password_field :password %>
      </li>
      <li>
        <%= f.label :password_confirmation %>
        <%= f.password_field :password_confirmation %>
      </li>
      <li>
        <%= f.submit 'Register' %>
      </li>
    </ul>
  <% end %>
</div>

For whatever reason the email gets set to nil every time a user is registered. The only that looks like it deals with the email is the field on the view, and the validation so I don’t know if maybe the validation is stripping it and no error is being thrown.

The :login_required method sits in my application_controller and is a check to make sure the user is logged in for the session. The skip_filter is to not check that when going to the sign in and registeration pages.

Any ideas? Thanks in advance.

  • 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-27T03:33:36+00:00Added an answer on May 27, 2026 at 3:33 am

    You’ve written:

    attr_accessor :email, :password, :password_confirmation
    

    Have you tried removing the email parameter from this list? It’s probably overriding AR’s persistence for the email attribute. You may want attr_accessible instead for email.

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

Sidebar

Related Questions

I am trying to convert my custom simple auth system in my rails app
I'm working on a simple custom shopping cart (yes, reinventing the wheel) in Rails.
I'm trying to make a custom simple toggle buttons with addClass and removeClass. The
I am currently working on some simple custom allocators in c++ which generally works
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display
i am working on a simple web app which has a user model and
I have a simple create user wizard and custom membership provider which was taken
I'm working with a custom checkbox, and I'm trying to set the content to
I'm working on a site with a simple php-generated twitter box with user timeline

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.