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角度或軌道?只用我選擇的參數更新模型是可能的?