Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View commands.sh
1 2 3 4 5 6 7 8 9 10 11
$ rails console --sandbox
 
>> User.all
User Load (0.1ms) SELECT "users".* FROM "users"
=> #<ActiveRecord::Relation [#<User id: 1, name: "Prasanth", email: "nagu89@gmail.com", created_at: "2013-05-18 15:37:19", updated_at: "2013-05-18 15:37:19">, #<User id: 2, name: "Chick Norris", email: "gmail@chuck.com", created_at: "2013-05-18 15:38:44", updated_at: "2013-05-18 15:38:44">]>
# above command proves that user does exist
>> user = User.new
=> #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
>> user = User.new({:name => "superman", :email => "superman@krypton.net"})
=> #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
# the attributes hash is not getting used at all. Cant figure out why
View commands.sh
1 2 3 4 5 6 7 8 9 10 11 12
class User < ActiveRecord::Base
attr_accessor :name, :email
 
def after_initialize(attributes = {})
self[:name] = attributes[:name]
self[:email] = attributes[:email]
end
 
def formatted_email
"#{self.name} <#{self.email}>"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.