0
我想用Restangular发出一个修补程序请求来更新用户属性。所以,写这样的:Restangular + rails:未知属性错误
user.patch(user: user).then(function (result) ...
我使用的轨道葡萄框架和我的控制器看起来像这样:
desc 'Update a user'
params do
requires :user, type: Hash, desc: "user attributes" do
optional :email, type: String, allow_blank: false, regexp: /[email protected]+/, documentation: { example: '[email protected]' }
optional :password, type: String, allow_blank: false
optional :firstname, type: String
optional :lastname, type: String
optional :city, type: String
optional :date_of_birth, type: Date
end
end
patch ':id' do
puts params.to_h
user = User.find(params[:id])
user.update(params[:user].to_h)
user
end
不幸的是,我没有atrribute路线我在我的用户模型,所以导轨显示此错误:
ActiveRecord::UnknownAttributeError (unknown attribute: route):
app/controllers/api/v1/users.rb:44:in `block (2 levels) in <class:Users>'
我该怎么办?删除这个atrribute角度或轨道?只用我选择的参数更新模型是可能的?