我希望在使用inherited_resources的Rails应用程序中使用REST,但我希望某些属性不会在json和xml请求期间暴露出来。
让我们将该字段命名为“password”。
我知道我可以重写to_xml和to_json方法,然后
super :except => [:password]但我必须为to_xml和to_json这样做。不是很干。
有什么想法吗?
rest_member_defaults :except => [:password]大概就是我想要的。
谢谢!
发布于 2011-05-18 01:35:56
我有这个确切的问题,你的问题触发了我把它包装成一个插件hide_attributes,它也可以作为一个宝石。
只需将其添加到您的Gemfile
gem 'hide_attributes'然后在你的模型中添加类似这样的东西:
class User < ActiveRecord::Base
hide_attributes :password, :password_salt
end这就对了。很抱歉,目前还没有测试,文档也很少。
https://stackoverflow.com/questions/3531114
复制相似问题