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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:28:51+00:00 2026-06-11T14:28:51+00:00

this is a simple signup application schema.rb create_table users, :force => true do |t|

  • 0

this is a simple signup application

schema.rb

create_table "users", :force => true do |t|
t.string   "email"
t.string   "password_hash"
t.string   "password_salt"
t.datetime "created_at",    :null => false
t.datetime "updated_at",    :null => false

User.rb

attr_accessible :email, :password, :password_confirmation
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
.
.
.

Why using password in both attr_accessible and attr_accessor?

When i removed attr_accessor :password, in rails console, i got an error when executing:

user = User.new
user.password # => no method error

but when i execute this:

user = User.new
user.email # => nil

which means user.email working without adding it in attr_accessor, why?!!

and also this is working:

user = User.new
user.password_confirmation # => nil

but when i removed:

validates_confirmation_of :password

it will not work, why??.

  • 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-11T14:28:53+00:00Added an answer on June 11, 2026 at 2:28 pm

    attr_accessor and attr_accessible, despite almost identical spelling, are absolutely different methods.

    attr_accessor, a native Ruby method which defines a getter and a setter method for the instance of the class:

    class User
      attr_accessor :password
    end
    
    u = User.new
    u.password = "secret"
    u.password # => "secret"
    

    attr_accessible is a method brought by Rails and it is meant to “whitelist” already existing attributes of a model. Attributes enumerated in attr_accessible can be later changed via mass-assignment of model attributes (while other attributes will be blacklisted and not changeable):

    class Account < ActiveRecord::Base
      # First, you define 2 attributes: "password" and "created_at"
      attr_accessor :password
      attr_accessor :created_at
    
      # Now you say that you want "password" attribute
      # to be changeable via mass-assignment, while making
      # "created_at" to be non-changeable via mass-assignment
      attr_accessible :password
    end
    
    a = Account.new
    
    # Perform mass-assignment (which is usually done when you update
    # your model using the attributes submitted via a web form)
    a.update_attributes(:password => "secret", :created_at => Time.now)
    
    a.password # => "secret"
    # "password" is changed
    
    a.created_at # => nil
    # "created_at" remains not changed
    

    You use attr_accessible to prevent meddling with some attributes of your models by “outsiders” (e.g. you wouldn’t want your “Account.superadmin” attribute to be changeable via a simple form submission, which would be a bad security issue).

    Note, that you can change the attributes individually, regardless of their “whitelisting/blacklisting” status:

    a.created_at = Time.now
    
    a.created_at # => 2012-09-16 10:03:14
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This simple regex matching returns a string instead of an object on every browser
In this simple example, i want to create a String array populated with each
Consider this simple example - public class Person { private String name; private Date
I have a simple application using the Play! framework's secure module. My 'Users' controller
I'm practicing my Ruby on Rails by creating a simple application where users can
I'm building a simple signup application on my website with user database. I'm using
This simple query session = com.jthink.songlayer.hibernate.HibernateUtil.getSession(); Query q = session.createQuery(recNo from SongChanges); giving this
This simple script should theoretically check the form for errors and then print any
This simple example fails to compile in VS2K8: io_service io2; shared_ptr<asio::deadline_timer> dt(make_shared<asio::deadline_timer>(io2, posix_time::seconds(20))); As
This simple Python method I put together just checks to see if Tomcat is

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.