I'm creating a sample_app with railstutorial.org and I have a small problem with creating a new User in Rails 4. I'm in a chapter 6: http://ruby.railstutorial.org/chapters/modeling-users#sec-the_model_file
After creating a new user in Rails console for example:
user = User.new(name: "Example", email: "email@example.com")
I got:
#<User id: 2, name: nil, email: nil, created_at: "2013-12-29 19:53:25", updated_at: "2013-12-29 19:53:25">
So that's mean, that I've just created a new user with nil params, but I initialized a name and email....
but when I type:
user.name
I got:
user.name
=> "Example"
also in sqlite3 data browser application I see only an empty columns.
My user.rb looks like:
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}
#:uniqueness => true
validates :email, :presence => true,
:format => {with: email_regex},
:uniqueness => {:case_sensitive => false}
end
So what's wrong? Any idea how to fix that?