我的问题是,由于没有自动设置的属性,我总是会收到downloadByBusinessFlowId: function (req, res) {
var AWS = require('aws-sdk');
AWS.config.update({accessKeyId: sails.config.AwsCredential.AWS_ACCESS_KEY_ID, secretAccessKey: sails.config.AwsCredential.AWS_SECRET_ACCESS_KEY});
var s3 = new AWS.S3();
var params = {
Bucket: sails.config.AwsCredential.bucket_name,
Prefix: 'cc_' + req.param('cc')
}
const signedUrlExpireSeconds = 60 * 5;
// console.log(url)
var result = [];
s3.listObjects(params, function (err, data) {
if(err)throw err;
dataLength = data.Contents.length;
var flag = false;
for(var i = 0; i < dataLength; i++){
//need logic here and put url in json
}
console.log(result);
return res.json(result);
});
},
值。以下是一些例子:
nil
以下是我在示例中使用的模型:
2.3.1 :001 > t = Team.new(name: "team_1", code: "a123")
=> #<Team _id: 581b2f230640fd0cf4070a47, created_at: nil, updated_at: nil, code: nil, name: nil>
2.3.1 :002 > t.save
=> true
2.3.1 :003 > t
=> #<Team _id: 581b2f230640fd0cf4070a47, created_at: 2016-11-03 12:35:58 UTC, updated_at: 2016-11-03 12:35:58 UTC, code: nil, name: nil>
2.3.1 :004 > t.name = "team_1"
=> "team_1"
2.3.1 :005 > t
=> #<Team _id: 581b2f230640fd0cf4070a47, created_at: 2016-11-03 12:35:58 UTC, updated_at: 2016-11-03 12:35:58 UTC, code: nil, name: nil>
我的Gemfile:
class Team
include Mongoid::Document
include Mongoid::Timestamps
attr_accessor :name, :code, :owner_id, :learnin_object_ids, :active
field :code, type: String
field :name, type: String
end
如何保存正确的数据?
答案 0 :(得分:0)
问题是由于attr_accessor
造成的。删除后,将保存正确的数据。