2010-08-20 99 views
0

我想在使用inherited_resources, 的Rails應用程序中使用REST,但我希望在json和xml請求期間不會顯示某些屬性。從inherited_resources隱藏屬性的方法

我們稱之爲「密碼」字段。

我知道我可以覆蓋to_xml和to_json方法,然後

super :except => [:password] 

我願意做就是to_xml和to_json。不是很乾。

任何想法?

rest_member_defaults :except => [:password] 

在控制器裏隱約有我的目標。

謝謝!

回答

0

我有這個確切的問題,你的觸發我把它包裝成一個插件hide_attributes這也是一個寶石。

只需將它添加到您的Gemfile

gem 'hide_attributes' 

然後添加像這樣到你的模型:

class User < ActiveRecord::Base 
    hide_attributes :password, :password_salt 
end 

而且你去那裏。很抱歉,還沒有測試,文檔相當薄弱。