Question

My user.rb looks like this:

class User < ActiveRecord::Base
  attr_accessible :password, :password_confirmation, :crypted_password, :username, :password_salt, :persistence_token
  acts_as_authentic
  has_many :assignments
  has_many :roles, :through => :assignments
  def role_symbols
    roles.map do |role|
      role.name.underscore.to_sym
    end
  end  
end

But I get this in rails console:

x = User.create(:username => "foo", :password => "bar", :password_confirmation => "bar")
   (0.2ms)  BEGIN
  User Exists (0.4ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."username") = LOWER('foo') LIMIT 1
  User Exists (0.6ms)  SELECT 1 AS one FROM "users" WHERE "users"."persistence_token" = 'e3c363da87d37fc7f17d3d1f4d4c851b93cf974ae614ec0b0cb9eb1935dd2dc2ccab34d0a06b4580881dc38e5b65027cce0f2e53a005860fc81d7f5e4c245d6a' LIMIT 1
   (0.3ms)  ROLLBACK
+----+----------+---------+---------+---------+-------+---------+---------+
| id | username | cryp... | pass... | pers... | email | crea... | upda... |
+----+----------+---------+---------+---------+-------+---------+---------+
|    | foo      | 6196... | vIzV... | e3c3... |       |         |         |
+----+----------+---------+---------+---------+-------+---------+---------+
1 row in set
1.9.3-p194 :031 > User.all
  User Load (1.5ms)  SELECT "users".* FROM "users" 
 => [] 
1.9.3-p194 :032 > x.save
   (0.1ms)  BEGIN
  User Exists (0.6ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."username") = LOWER('foo') LIMIT 1
  User Exists (0.3ms)  SELECT 1 AS one FROM "users" WHERE "users"."persistence_token" = 'e3c363da87d37fc7f17d3d1f4d4c851b93cf974ae614ec0b0cb9eb1935dd2dc2ccab34d0a06b4580881dc38e5b65027cce0f2e53a005860fc81d7f5e4c245d6a' LIMIT 1
   (0.1ms)  ROLLBACK
 => false 
Was it helpful?

Solution

Realised that :email needed an attr_accessible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top