I am using Ruby on Rails 3 and I followed the Tableless models in Rails istructions in order to apply that to a my model Account.
All works, but if I do
@test = account.id
a debug of @test
results in a nil value and seems not accessible at all.
In a comment of this question @Wukerplank said:
You are right. I suppose id has a special status in ActiveRecord. I think it would only be set after the record is persisted in some database.
How can I retrive\access the id attribute value?
UPDATED
Trying and re-trying I discovered that a possible solution is to make all attributes 'attr_accessible' (if I make just the 'id', I get all other value 'nil'), but I think it is a very dangerous solution.
Anoth开发者_如何转开发er solution is to create a new class attribute that acts as the id
, but why I have to do that if I have already the id?!
Why don't you use ActiveModel instead? Check this screencast.
精彩评论