Ruby on Rails Tuesday, November 30, 2010

> UserSkill.new # => { :id => nil, :user_id => nil, :skill_id => nil }
> us = UserSkill.create(:user_id => 1, :skill_id => 1) # => { :id => nil,
> :user_id => 1, :skill_id => 1 }
>
> Why id is nil?
> In the database record was created and id is not null...


Hi,

Friend when you create any "new" object usign UserSkill or any class
class
which is associated with ActiveRecords.. then it auto create one hash
with all attributes of user_skills(or any relevant) table.. this is due
to ORM feature of the Rails..

Second thing, that all values seems to nil in that hash.. this is
because it provide you blank hash.. to do process or to assign required
values to
the attributes..

nil is just because as we know ruby has greate feature of NilClass to
avoid exceptions on nil values..


I dont know is this answer of your question or not.

Good luck ;)

-Ganesh K.

--
Posted via http://www.ruby-forum.com/.

--
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.

No comments:

Post a Comment