[Rails] Data in my object but not the db - help!
I'm a newbie learning Rails3 and this issue has my learning stopped in
its tracks, so I'd greatly appreciate your help. I have a simple test
app with a User model and name and email fields. In the console, if I
run
@test = User.create!(:name => 'Test Testman', :email =>
'test@test.com')
I get
=> #<User id: 21, name: nil, email: nil, created_at: "2011-01-09
03:48:00", updated_at: "2011-01-09 03:48:00">.
Where did my name and email data go? If I check the object I just
created in the console,
@test.name
returns
=> "Test Testman"
so it made it that far, and it also passed my model validation.
Looking at the development log, I see NIL values for these fields in
the SQL. Looking at the DB, I have rows being created with IDs and
dates, but no name & email. How could data be present in the object
but not get written into the SQL? My environment is running Ruby
1.9.2, Rails 3.0.3 and sqlite3-ruby 1.3.2 (I updated everything in an
attempt to fix this) . Anyone ever see behavior like this and know the
fix?
Here's all I'm trying to do:
class User < ActiveRecord::Base
attr_accessor :name, :email
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name,
:presence => true,
:length => { :maximum => 50 }
validates :email,
:presence => true,
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
end
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home