Forum: Ruby on Rails Reading n writing object attributes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8106f37727c11d8c293326a06a1c1ffa?d=identicon&s=25 Soh Dubom (sohdubom)
on 2008-10-28 02:49
Reading n writing object attributes

Hi. In this simple example I have a User class with the class method:

  def self.find_user(name)
    user = self.find(:first, :conditions => ["username = ?", name])
    # user.salt
  end

In the rails console I do the following:

>> u = User.find_user('kena')
=> #<User id: 5, username: "test", hashed_password:
"c1a18d933c06f5a3ebd8d1d155d294f39447fbf2", salt:
"177647700.129851651671097", email: "", created_at: "2008-10-28
00:54:42", updated_at: "2008-10-28 00:54:42">
>> u.salt
=> nil
>> u.username
=> nil

What I don't understand is why I can't access its attributes?
F47bebf5f4b10b709a59310027c8f977?d=identicon&s=25 Robert Zotter (Guest)
on 2008-10-28 04:11
(Received via mailing list)
Soh,

Not sure why you are not able to access the attributes in the use case
but can I ask why you are not using the dynamic find_by methods ie
User.find_by_username('kena')  ?

--
Robert Zotter
Zapient, LLC
Ruby on Rails Development and Consulting

On Oct 27, 6:49 pm, Soh Dubom <rails-mailing-l...@andreas-s.net>
8106f37727c11d8c293326a06a1c1ffa?d=identicon&s=25 Soh Dubom (sohdubom)
on 2008-10-28 13:36
Robert Zotter wrote:
> Soh,
>
> Not sure why you are not able to access the attributes in the use case
> but can I ask why you are not using the dynamic find_by methods ie
> User.find_by_username('kena')  ?
>
> --
> Robert Zotter
> Zapient, LLC
> Ruby on Rails Development and Consulting
>
> On Oct 27, 6:49�pm, Soh Dubom <rails-mailing-l...@andreas-s.net>

I will definitely use the dynamic method, but I was just wondering why
the other way was going wrong. I didn't have any private nor protected
methods and I was reloading my console with: reload! ... I then decided
to re-start my machine and now it works fine. Unfortunately I cannot
reproduce that problem now ... let's consider that a good thing ...
thanks anyway :-)
This topic is locked and can not be replied to.