I have initialized my parse-ruby-client with my Parse API key and Client ID.
Here is the code for saving a date:
dbObject = MyParse.object("ClassName")
dbObject["startTime"] = Date.new
result = dbObject.save
However I get the following error on the second line:
Parse::ParseProtocolError in EventsController#create<br> 111: invalid type for key startTime, expected date, but got string
The error prompt you: for dbObject["startTime"]
, the key("startTime") should be a date type, but "startTime" is a string type.
You should change dbObject["startTime"]
to dbObject[Date.new]
(or other data type value) depend on your needs.
I was able to save the start time of my event to Parse by writing and calling a cloud code function instead of saving the value directly from the .rb file.
events_controller.rb:
params = {"name" => @event.name,
"startTime" => @event.startTime}
function = Parse::Cloud::Function.new("createEvent")
function.call(params)
cloud_code.js:
Parse.Cloud.define("createEvent", function(req, res) {
var name = req.params.name;
var startTime = new Date(req.params.startTime);
var parseClass = Parse.Object.extend("ClassName");
var event = new parseClass();
event.set('name', name);
event.set('startTime', startTime);
event.save(null, {
success: function(event) {
res.success('Successfully ran createEvent');
},
error: function(event, error) {
res.error(error);
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.