2011-03-04 79 views
0

我正在使用Ruby on Rails 3,並且我遵循Tableless models in Rails istructions以將其應用於我的模型帳戶。無法訪問Tableless模型的ID值

所有的作品,但如果我不

@test = account.id 

@test結果的調試在價值,似乎無法訪問的。


this question @Wukerplank的評論說:

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. 

我怎麼能retrive \訪問id屬性值?


修訂

嘗試並重新嘗試,我發現一個可能的解決方案是讓所有屬性「attr_accessible」(如果我只是「身份證」,我得到的所有其他價值「零「),但我認爲這是一個非常危險的解決方案。

另一種解決方案是創建一個新的類屬性,作爲id,但爲什麼我必須這樣做,如果我已經是ID?!

回答

0

爲什麼不使用ActiveModel呢?檢查this截屏視頻。

+0

ActiveModel不支持關聯 – capzulu 2014-03-14 12:39:17